I am creating an application in which I can move the Labels
that are on a PictureBox
.
The problem is that I want these to only Labels move inside the PictureBox
.
Here is my code:
protected void lbl_MouseMove(object sender, MouseEventArgs e)
{
Label lbl = sender as Label;
try
{
if (lbl != null && e.Button == MouseButtons.Left)
{
if (m_lblLocation != new Point(0, 0))
{
Point newLocation = lbl.Location;
newLocation.X = newLocation.X + e.X - m_lblLocation.X;
newLocation.Y = newLocation.Y + e.Y - m_lblLocation.Y;
lbl.Location = newLocation;
this.Refresh();
}
}
}
catch(Exception ex) { }
}
protected void lbl_MouseUp(object sender, MouseEventArgs e)
{
Label lbl = sender as Label;
try
{
if (lbl != null && e.Button == MouseButtons.Left)
{
m_lblLocation = Point.Empty;
}
}
catch(Exception ex) { }
}
protected void lbl_MouseDown(object sender, MouseEventArgs e)
{
Label lbl = sender as Label;
try
{
if (lbl != null && e.Button == MouseButtons.Left)
{
m_lblLocation = e.Location;
}
}
catch(Exception ex) { }
}
In above code I have created some mouse events for the Labels.