[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect); [DllImport("user32.dll")] public static extern bool GetCursorPos(out System.Drawing.Point lpPoint); [DllImport("user32.dll")] public static extern bool PtInRect(ref RECT lprc, System.Drawing.Point pt); [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; } private RECT m_rect = new RECT();
private void Form1_MouseLeave(object sender, EventArgs e)
{
this.Opacity = 0;
} private void Form1_MouseHover(object sender, EventArgs e)
{
this.Opacity = 100;
}
我定制了两个事件...为什么感觉Form1_MouseHover好像没有发生....就是当鼠标停留在窗体上的时候窗体没有再现出来....
private void Form1_MouseLeave(object sender, EventArgs e)
{ this.Opacity = 0.1; }
private void Form1_MouseHover(object sender, EventArgs e)
{ this.Opacity = 1; }效果还可以
用MouseMove代替Hover事件更敏感
{
this.Opacity = 0.1;//如果等于0,隐藏之后再不响应了
//MouseEnter,MouseHover,MouseMove
}
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect); [DllImport("user32.dll")]
public static extern bool GetCursorPos(out System.Drawing.Point lpPoint); [DllImport("user32.dll")]
public static extern bool PtInRect(ref RECT lprc, System.Drawing.Point pt); [StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
} private RECT m_rect = new RECT();
private void Form1_MouseLeave(object sender, EventArgs e)
{
GetWindowRect(new HandleRef(this, this.Handle), out m_rect);
timer1.Enabled = true;
this.Hide();
} private void timer1_Tick(object sender, EventArgs e)
{
if(m_rect.Left<=0 || m_rect.Top<=0 || m_rect.Right<=0 || m_rect.Bottom<=0)
return; System.Drawing.Point point = new Point();
GetCursorPos(out point);
if (PtInRect(ref m_rect, point))
{
this.Visible = true;
timer1.Enabled = false; m_rect.Left = 0;
m_rect.Top = 0;
m_rect.Right = 0;
m_rect.Bottom = 0;
}
}
这个说的对,如果hide的话,第一次隐藏之后,再到原位置上估计就没反应了
http://www.cnblogs.com/hnNet/articles/1511232.html仅供参考!
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
[/align]
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
[/align]