| View previous topic :: View next topic |
| Author |
Message |
Morph.C Cheater
Reputation: 0
Joined: 15 Aug 2009 Posts: 29
|
Posted: Sat Sep 12, 2009 6:51 pm Post subject: [C#] Drag a button inside the form. |
|
|
Well, in the title as specified in a nutshell, here I hope your understand me.
I have a button, which has an image, then, to give click to button (without drop the click), I want to move the mouse, move the button. until where release the mouse again.
I hope understand me, thanks in advance. and sorry for my english, but I speak Spanish.
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Sep 12, 2009 8:51 pm Post subject: |
|
|
| Code: | bool pDragging = false;
Point pMousePosition = Point.Empty;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
pMousePosition = button1.PointToClient(Control.MousePosition);
pDragging = true;
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
pDragging = false;
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (pDragging && e.Button == MouseButtons.Left)
{
Point theFormPosition = this.PointToClient(Control.MousePosition);
theFormPosition.X -= pMousePosition.X;
theFormPosition.Y -= pMousePosition.Y;
button1.Location = theFormPosition;
}
} |
I'd encapsulate this in a custom button class, to make it more reusable.
|
|
| Back to top |
|
 |
Morph.C Cheater
Reputation: 0
Joined: 15 Aug 2009 Posts: 29
|
Posted: Sun Sep 13, 2009 2:32 am Post subject: |
|
|
Works!! thanks!!!
|
|
| Back to top |
|
 |
|