110,525
社区成员
发帖
与我相关
我的任务
分享
[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)
{
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;
}
}
private void Form1_MouseLeave(object sender, EventArgs e)
{
this.Opacity = 0.1;//如果等于0,隐藏之后再不响应了
//MouseEnter,MouseHover,MouseMove
}