自定义Windows Form没法拖动,简单解决方案。

我也不知道为何要自定义一个没差的WinForm,反正就是遇到了MyForm没法用鼠标拖着走的问题,百度到的解决方案,记录一下:再把函数

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public 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;

        private void tab_title_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//*********************调用移动无窗体控件函数  
        }

再把tab_title_MouseDown方法给任务栏的MouseDown事件注册进去就行了:this

        public LargeIcoMainForm()
        {
            InitializeComponent();
            this.tab_title.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tab_title_MouseDown);
        }

完美。spa

相关文章
相关标签/搜索