Move the windowform

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;

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top