拖放不能用C#代码完成,会发生拖尾和延时现象解决方案。 直接调用windows Api [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public 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;Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); }
请问一下大家,这个public const int WM_SYSCOMMAND = 0x0112; 值在那里找的到啊,找了半天都没有找到 public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002;
如何写添加事件?
不明白.
参考:
private Point MousePos; //记录鼠标指针的坐标
private bool bMouseDown = false; //记录鼠标按键是否按下 private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{//响应鼠标按下
if (e.Button == MouseButtons.Left)
{
MousePos.X = -e.X - SystemInformation.FrameBorderSize.Width;
MousePos.Y = -e.Y - SystemInformation.CaptionHeight -SystemInformation.FrameBorderSize.Height;
bMouseDown = true;
}
} private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{//响应鼠标移动
if (bMouseDown)
{
Point CurrentPos = Control.MousePosition;
CurrentPos.Offset( MousePos.X, MousePos.Y);
Location = CurrentPos; }
} private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{//响应鼠标弹起
if (e.Button == MouseButtons.Left)
{
bMouseDown = false;
}
}
直接调用windows Api
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public 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;Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;