1. 添加Using 声明

using System.Runtime.InteropServices;

 

2.在类中加入如下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;

 

3.在需要拖动的Form或控件的MouseDown事件中加入以下代码:

       

ReleaseCapture();         
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE +HTCAPTION,0);

 

完成;

 

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案