daily pastebin goal
44%
SHARE
TWEET

FormBorderStyle None form move #2

tolikpunkoff Jan 27th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top