How do I make mousedrag inside Panel move form window?

后端 未结 5 921
陌清茗
陌清茗 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:12

    You can achieve it by using the MouseMove Event of the panel

    Example should be something like this (Sorry have not tested it)

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            this.Location = new Point(Cursor.Position.X + e.X , Cursor.Position.Y + e.Y);
        }
    }
    

提交回复
热议问题