//****************************************************
    //创建人:xxx
    //****************************************************
    public partial class MyForm : Form
    {
        /// <summary>
        /// 释放鼠标捕获
         /// </summary>
        /// <returns>成功返回true,失败返回false</returns>
        [DllImport("user32.dll")]
        public static extern Boolean ReleaseCapture();

        /// <summary>
        /// 向窗体发送消息
         /// </summary>
        /// <param name="hwnd">窗体的句柄</param>
        /// <param name="wMsg">消息号</param>
        /// <param name="wParam">消息的附加信息</param>
        /// <param name="lParam">消息的附加信息</param>
        /// <returns>成功返回true,失败返回false</returns>
        [DllImport("user32.dll")]
        public static extern Boolean SendMessage(IntPtr hwnd, Int32 wMsg, Int32 wParam, Int32 lParam);

        public const Int32 WM_SYSCOMMAND = 0x0112;

        public const Int32 SC_MOVE = 0xF010;

        public const Int32 HTCAPTION = 0x0002;

        /// <summary>
        /// 窗体的鼠标点击事件委托
         /// </summary>
        private void panelTitle_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }
}

 

posted on 2019-01-09 16:31  天涯浪子1955  阅读(273)  评论(0编辑  收藏  举报