I wanna move a control on a Form at runtime.
Any Advice
I wanna move a control on a Form at runtime.
Any Advice
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
YoavPosted Apr 22, 2008, 4:16 AM
private bool inDrag = false;
private int xLoc;
private int yLoc;
private void State_MouseDown(object sender, MouseEventArgs e)
{
}
private void State_MouseMove(object sender, MouseEventArgs e)
{
if (inDrag)
{
this.Top += e.Y - yLoc;
this.Left += e.X - xLoc;
}
}
private void State_MouseUp(object sender, MouseEventArgs e)
{
inDrag = false;
}
Ahmad MobadderPosted Apr 12, 2008, 11:45 AM
thanks alot i'm using this on the control
private void State_MouseMove(object sender, MouseEventArgs e){
if (e.Button == MouseButtons.Left){
this.Location = new Point(e.X, e.Y);}
}
but it's not accurate, the control is fricling and not where i release the mouse it stay any more ideas thanks again..
Mike GoldPosted Apr 5, 2008, 11:18 PM
I believe all you need to do is set the Location property of the control
myControl.Location = new Point(x, y);
Just make sure you do it after the OnLoad event has occurred in the form