无标题Form拖动控制

前段时间需要用窗体来实现消息弹窗,没办法Form实在太丑了,得把它隐藏掉,可隐藏掉之后就没有办法拖动了,到网上搜索了一下资料,实现拖动方法还是挺简单的,通过api来实现即可:

        [DllImport("user32")]
        private static extern bool ReleaseCapture();

        [DllImport("user32")]
        private 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;

        //假设有一个panel 或label,在它的mousedown事件中,调用上面的函数即可

        private void panel2_MouseDown(object sender, MouseEventArgs e)
        {
            if (!this.IsDisposed)
            {
                ReleaseCapture();
                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
            }
        }

posted @ 2011-03-15 20:05  freeman_rain  阅读(222)  评论(0编辑  收藏  举报