解决方案 »

  1.   

      private Point mPoint = new Point();
     
             private void Form1_MouseDown(object sender, MouseEventArgs e)
             {
                 mPoint.X = e.X;
                 mPoint.Y = e.Y;
             }
     
             private void Form1_MouseMove(object sender, MouseEventArgs e)
             {
                 if (e.Button == MouseButtons.Left)
                 {
                     Point myPosittion = MousePosition;
                     myPosittion.Offset(-mPoint.X, -mPoint.Y);
                     Location = myPosittion;
                 } 
             }试试。其实我的想法,就是鼠标在移动时,计算窗体的位置就行了
      

  2.   

            /// <summary>
            /// 移动窗体
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void MainForm_MouseDown(object sender, MouseEventArgs e)
            {            Win32.ReleaseCapture();
                Win32.SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);        }
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
        public static class Win32
        {
            /// <summary>
            /// 释放鼠标操作
            /// </summary>
            /// <returns></returns>
            [DllImport("user32.dll")]
            public static extern bool ReleaseCapture();
            /// <summary>
            /// 发送信息
            /// </summary>
            /// <param name="hwnd"></param>
            /// <param name="wMsg"></param>
            /// <param name="wParam"></param>
            /// <param name="lParam"></param>
            /// <returns></returns>
            [DllImport("user32.dll")]
            public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
            /// <summary>
            /// 窗体最小化操作
            /// </summary>
            /// <param name="hwnd"></param>
            /// <returns></returns>
            [DllImport("user32.dll")]
            public static extern bool CloseWindow(IntPtr hwnd);
            /// <summary>
            /// 获取窗体状态信息|最小化|最大化|移动|关闭
            /// </summary>
            /// <param name="hwnd"></param>
            /// <param name="nindex"></param>
            /// <returns></returns>
            [DllImport("user32.dll")]
            public static extern int GetWindowLong(HandleRef hwnd, int nindex);
            /// <summary>
            /// 设置窗体状态信息|最小化|最大化|移动|关闭|系统右键菜单
            /// </summary>
            /// <param name="hwnd"></param>
            /// <param name="nindex"></param>
            /// <param name="dwNewLong"></param>
            /// <returns></returns>
            [DllImport("user32.dll")]
            public static extern int SetWindowLong(HandleRef hwnd, int nindex, int dwNewLong);
            /// <summary>
            /// 获取窗体句柄
            /// </summary>
            /// <param name="hWnd"></param>
            /// <returns></returns>
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern IntPtr GetWindowDC(IntPtr hWnd);
            /// <summary>
            /// 释放窗体句柄
            /// </summary>
            /// <param name="hWnd"></param>
            /// <param name="hDC"></param>
            /// <returns></returns>
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
        }