Winform: How to move user control at runtime

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
i am showing my user control onto form but that is fixed. requirement is user should be able to move user control by mouse.

i did it this way but not working properly

_uc = new ucEditLiConfig();
_uc.MouseDown += new System.Windows.Forms.MouseEventHandler(this.uc_MouseDown);
_uc.MouseMove += new System.Windows.Forms.MouseEventHandler(this.uc_MouseMove);
_uc.MouseUp += new System.Windows.Forms.MouseEventHandler(this.uc_MouseUp);
this.Controls.Add(_uc);
_uc.Visible = false;

// positioning user control
_uc.Location = new Point(
this.Width / 2 - _uc.Size.Width / 2,
this.Height / 2 - _uc.Size.Height / 2);
_uc.BringToFront();

_uc.Visible = true;



private void uc_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true)
{
if (_uc!=null )
_uc.Location = new Point(e.X, e.Y);
}
}

private void uc_MouseDown(object sender, MouseEventArgs e)
{
isMouseDown = true;
}

private void uc_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}


please share some code which i can used to get smooth movement of user control by user at runtime. thanks

Continue reading...
 
Back
Top