c# - how to restrict child control inside Parent control in Winform application? -
i've created label controls dynamically inside panel control. i'm moving label controls using mouse events. time label control moving outside panel control. how can restrict it?
you can take benefit of cursor.clip
requirement (although can handle manually in mousemove
event handler):
point downpoint; //mousedown event handler label1 private void label1_mousedown(object sender, mouseeventargs e){ downpoint = e.location; //this important code make works cursor.clip = yourpanel.rectangletoscreen(new rectangle(e.x, e.y, yourpanel.clientsize.width - label1.width, yourpanel.clientsize.height - label1.height)); } //mousemove event handler label1 private void label1_mousemove(object sender, mouseeventargs e) { if (e.button == mousebuttons.left) { label1.left += e.x - downpoint.x; label1.top += e.y - downpoint.y; } } //mouseup event handler label1 private void label1_mouseup(object sender, mouseeventargs e){ cursor.clip = rectangle.empty; }
Comments
Post a Comment