Make a borderless form movable?

前端 未结 21 1822
情歌与酒
情歌与酒 2020-11-22 09:48

Is there a way to make a form that has no border (FormBorderStyle is set to \"none\") movable when the mouse is clicked down on the form just as if there was a border?

21条回答
  •  死守一世寂寞
    2020-11-22 10:23

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/d803d869-68e6-46ff-9ff1-fabf78d6393c/how-to-make-a-borderless-form-in-c?forum=csharpgeneral

    This bit of code from the above link did the trick in my case :)

    protected override void OnMouseDown(MouseEventArgs e)  
    
    {
          base.OnMouseDown(e);
          if (e.Button == MouseButtons.Left)
          {
            this.Capture = false;
            Message msg = Message.Create(this.Handle, 0XA1, new IntPtr(2), IntPtr.Zero);
            this.WndProc(ref msg);
          }
    }
    

提交回复
热议问题