SoFunction
Updated on 2025-03-06

C# Winform window movement method

After we hide the borders that come with Winform, we need to write the movement of the window ourselves.

The idea is

1. Obtain the coordinates of the current mouse when clicking the left button

2. Obtain the coordinates of the mouse after moving

3. The coordinates of the form = the mouse coordinates after moving - the mouse coordinates before moving

private Point mouseOff;//Mouse Move Position Variable  private bool leftFlag;//Is the mouse left key  private void Form1_MouseDown(object sender, MouseEventArgs e)
  {
   if( == )
   {
    mouseOff = new Point(-, -);//Get the coordinates of the current mouse    leftFlag = true;
   }
  }

  private void Form1_MouseMove(object sender, MouseEventArgs e)
  {
   if (leftFlag)
   {
    Point mouseSet = ;//Get the coordinates of the mouse after moving    (, );//Set the position after moving    Location = mouseSet;
   }
  }

  private void Form1_MouseUp(object sender, MouseEventArgs e)
  {
   if (leftFlag)
   {
    leftFlag = false;
   }
  }

The above C# Winform window movement method is all the content I share with you. I hope you can give you a reference and I hope you can support me more.