自定义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事件注册进去就好了:

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

完美。

posted on 2017-01-04 10:59  Moral  阅读(556)  评论(1编辑  收藏  举报

导航