drag&move form without title bar[http://www.silmoon.com/site/Article/techatc/codeandprogram/DotNet/Article_271.html]
一
调用API消息
[DllImport("user32.dll")]
public extern static long SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
[DllImport("user32.dll")]
public extern static bool ReleaseCapture();
鼠标事件
this.Opacity = 0.2;
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, 0xF017, 0);
二
调用API消息
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wparam, int lparam);
重写的鼠标事件
protected override voidonMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e); if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
Capture = false;//释放鼠标,使能够手动操作
SendMessage(Handle, 0x00A1, 2, 0);//拖动窗体
}
}
三
公用定量
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
鼠标重写
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
return;
break;
}
base.WndProc(ref m);
}
四
重写鼠标事件
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0201://鼠标左键按下的消息
m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
m.LParam = IntPtr.Zero;//默认值
m.WParam = new IntPtr(2);//鼠标放在标题栏内
break;
}
base.WndProc(ref m);
}
调用API消息
[DllImport("user32.dll")]
public extern static long SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
[DllImport("user32.dll")]
public extern static bool ReleaseCapture();
鼠标事件
this.Opacity = 0.2;
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, 0xF017, 0);
二
调用API消息
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wparam, int lparam);
重写的鼠标事件
protected override voidonMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e); if (e.Button == MouseButtons.Left)//按下的是鼠标左键
{
Capture = false;//释放鼠标,使能够手动操作
SendMessage(Handle, 0x00A1, 2, 0);//拖动窗体
}
}
三
公用定量
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
鼠标重写
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
return;
break;
}
base.WndProc(ref m);
}
四
重写鼠标事件
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0201://鼠标左键按下的消息
m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
m.LParam = IntPtr.Zero;//默认值
m.WParam = new IntPtr(2);//鼠标放在标题栏内
break;
}
base.WndProc(ref m);
}
浙公网安备 33010602011771号