protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case 0xA1://WM_NCLBUTTONDOWN
case 0x84://WM_NCHITTEST
if (MouseButtons == MouseButtons.Left)//左鍵按下
{
var mousePoint = new Point((int)m.LParam);//鼠標位置(屏幕)
//NClientClick(mousePoint); //觸發響應的事件即可
}
break;
}
}
private Rectangle ScreenRectangle //控件在屏幕的區域
{
get
{
var r = new RECT();
GetWindowRect(new HandleRef(this, Handle), ref r);
var clientRect = new Rectangle(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top);
return clientRect;
}
}
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);
public struct RECT
{
/// <exclude/>
public int Left;
/// <exclude/>
public int Top;
/// <exclude/>
public int Right;
/// <exclude/>
public int Bottom;
}