无标题Form拖动控制
时间:2011-03-15 来源:freeman_rain
前段时间需要用窗体来实现消息弹窗,没办法Form实在太丑了,得把它隐藏掉,可隐藏掉之后就没有办法拖动了,到网上搜索了一下资料,实现拖动方法还是挺简单的,通过api来实现即可:
[DllImport("user32")]
private static extern bool ReleaseCapture();
[DllImport("user32")]
private static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0Xf010;
public const int HTCAPTION = 0x0002;
//假设有一个panel 或label,在它的mousedown事件中,调用上面的函数即可
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
if (!this.IsDisposed)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}