且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C# 窗体拖拽功能

更新时间:2022-09-14 19:11:15

#region - 拖拽功能实现Dll -
[Description("使能拖拽功能.")]
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
#endregion

 

public Form1()
{
   this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Window_CanDrap);

}

 

private void Window_CanDrap(object sender, MouseEventArgs e)
{
      const int WM_NCLBUTTONDOWN = 0x00A1;
      const int HT_CAPTION = 0x0002;
      ReleaseCapture();
      //传递左键按下事件
      SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}




本文转自黄聪博客园博客,原文链接:http://www.cnblogs.com/huangcong/archive/2010/03/26/1697077.html,如需转载请自行联系原作者