Move the windowform

  • Thread starter Thread starter cql90
  • Start date Start date
C

cql90

Hi All Pro,

First, thanks you all in advance for your kindest help, I am very
appreciated. I did have two event on the form, which are:
Form1_MouseDown(...) and Form1_MouseMove. The problem is: my form didn't
move at all when I do move the mouse. But, If I have a breakpoint at
mousedown, when I hit F5 to run the application, the form did move. What am
I doing wrong?

Kate,

Below is the code:

private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)

{

_MouseOffset = new Point( -e.X, -e.Y );

}

private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)

{

if( e.Button.Equals( MouseButtons.Left ) )

{

Point MousePos = Control.MousePosition;

MousePos.Offset( this._MouseOffset.X, this._MouseOffset.Y );

Location = MousePos;

}

}
 
Back
Top