class Form{
    private const int WM_NCHITTEST = 0x0084;
    private const int HTCAPTION = 0x0002;
    protected override void WndProc(ref Message m) {
 switch (m.Msg) {
     case WM_NCHITTEST:
  m.Result = (IntPtr) HTCAPTION;
  break;
     default:
  base.WndProc (ref m);
  break;
 }
    }
}

以上的代码是可以在form的客户区用鼠标移动窗体。

以下代码窗体上有个label 控件,拖拽 label 就能移动窗体

[System.Runtime.InteropServices.DllImport("user32.dll",EntryPoint="SendMessage")]
  public static extern int SendMessage(int hWnd,int wMsg,int wParam,int lParam);
  [System.Runtime.InteropServices.DllImport("user32.dll",EntryPoint="ReleaseCapture")]
  public static extern int ReleaseCapture();
  public const int WM_SysCommand = 0x0112;
  public const int SC_MOVE = 0xF012;

  private void label1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  {
   ReleaseCapture();
   SendMessage(this.Handle.ToInt32(),WM_SysCommand,SC_MOVE,0);
  }

相关文章:

  • 2021-08-23
  • 2021-08-22
  • 2022-02-08
  • 2022-12-23
  • 2021-10-01
  • 2021-03-31
  • 2022-12-23
猜你喜欢
  • 2021-11-10
  • 2021-08-18
  • 2022-12-23
  • 2021-05-27
  • 2021-06-26
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案