How do I make mousedrag inside Panel move form window?

后端 未结 5 925
陌清茗
陌清茗 2021-02-08 19:34

I have this System.Windows.Forms.Panel that I want to enable so that if the user click and drags the mouse drags the window around to.

Can I do this? Do i have to implem

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-08 20:18

    Currently Set For A Panel. VS C# Just Messing About Seems to work for me as I wanted Sets application left-top corner to mouse position while left-click is pressed.

     public form1()
        {
            InitializeComponent();
            this.panel2.MouseMove += new MouseEventHandler(panel2_MouseMove);
        }
        
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;
    
        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        
        private void panel2_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                
                Point loc1 = MousePosition;
                this.Location = loc1;
            }
        }
    

提交回复
热议问题