Make a borderless form movable?

前端 未结 21 2192
情歌与酒
情歌与酒 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:35

    public Point mouseLocation;
    private void frmInstallDevice_MouseDown(object sender, MouseEventArgs e)
    {
      mouseLocation = new Point(-e.X, -e.Y);
    }
    
    private void frmInstallDevice_MouseMove(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        Point mousePos = Control.MousePosition;
        mousePos.Offset(mouseLocation.X, mouseLocation.Y);
        Location = mousePos;
      }
    }
    

    this can solve ur problem....

提交回复
热议问题