ok, i have a button that i am dragging around. this much i can handle, but then i thought i would put it on a panel (like change the parent attribute) until the time came to use it and then when the button was clicked, it would set the parent to the main form (this)
the issue is when I do this, i can drag the button around ok if i drag very slowly, if i go to fast, the mouse comes off the button and the button no longer drags.
here is the main code. It uses a panel named panel1 and a button named button1
Code:
namespace focus_test
{
public partial class Form1 : Form
{
int xOffset, yOffset;
bool buttonClicked;
public Form1()
{
xOffset = yOffset = 0;
buttonClicked = false;
InitializeComponent();
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
xOffset = e.X;
yOffset = e.Y;
buttonClicked = true;
if (button1.Parent != this)
{
button1.Parent = this;
button1.Left += panel1.Left;
button1.Top += panel1.Top;
}
button1.BringToFront();
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
buttonClicked = false;
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (buttonClicked)
{
button1.Left += (e.X - xOffset);
button1.Top += (e.Y - yOffset);
}
}
}
}
to see what i am seeing, click on the button and hold down the mouse and drag it around. Going too fast (using the term "fast" loosely) the mouse will end up not over the piece any longer and not send a mouse move message to it anymore.
but
if you go over the button and let go of your mouse then click and drag again, you can go as fast as you want like the poor little mouse is welded to the button.
anyone got any clues as to why this is so?