日期:2014-05-18  浏览次数:20805 次

半百求解:有关于窗体的若干问题
1.怎样闪烁一个窗体在任务栏上的标题区?
2.如何像QQ那样实现窗体的自动隐藏?当鼠标移过去又能显示。


------解决方案--------------------
用win32api吧,c#实现不好
------解决方案--------------------
使用如下的方法就可以闪动窗体标题栏图标了:
[DllImport( "user32.dll ", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int FlashWindow(IntPtr hWnd);
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
FlashWindow(this.Handle);
}


自动隐藏,可以判断窗体所在区域上是否包含鼠标坐标,如果不包含则把窗体移到最近的屏幕的一边,然后留出一个5个像素左右的小边,以便当鼠标再次位于其上的时候还原窗体位置。

可以先得到指定窗体的大小区域的Rectangle,然后使用Rectangle.Contain来判断鼠标是否位于其上:
[DllImport( "user32.dll ", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool GetClientRect(IntPtr hWnd, [In, Out] COMRECT rect);

[StructLayout(LayoutKind.Sequential)]
public class COMRECT
{
public int left;
public int top;
public int right;
public int bottom;
public COMRECT()
{
}
public COMRECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}



------解决方案--------------------
路过,帮顶
------解决方案--------------------
mark
------解决方案--------------------
mark