Advertisement
tolikpunkoff

FormBorderStyle None form move #2

Jan 27th, 2018
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1.         private Point mouseOffset;
  2.         private bool isMouseDown = false;
  3.  
  4.  
  5.         private void frmTest_MouseDown(object sender, MouseEventArgs e)
  6.         {
  7.             int xOffset;
  8.             int yOffset;
  9.  
  10.             if (e.Button == MouseButtons.Left)
  11.             {
  12.                 xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
  13.                 yOffset = -e.Y - SystemInformation.CaptionHeight -
  14.                     SystemInformation.FrameBorderSize.Height;
  15.                 mouseOffset = new Point(xOffset, yOffset);
  16.                 isMouseDown = true;
  17.             }
  18.         }
  19.  
  20.         private void frmTest_MouseMove(object sender, MouseEventArgs e)
  21.         {
  22.             if (isMouseDown)
  23.             {
  24.                 Point mousePos = Control.MousePosition;
  25.                 mousePos.Offset(mouseOffset.X, mouseOffset.Y);
  26.                 Location = mousePos;
  27.             }
  28.         }
  29.  
  30.         private void frmTest_MouseUp(object sender, MouseEventArgs e)
  31.         {
  32.             if (e.Button == MouseButtons.Left)
  33.             {
  34.                 isMouseDown = false;
  35.             }
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement