How do I drag labels within a Panel in .Net?

Try to use the mouse to drag a label around during inside a panel. In VB6, just need to set the label DragMode to 1 and vb will take care of the X,Y position of the label. How do I do the same in .Net? Thanks a lot for your help.

2 Replies

CB Clay Burch Syncfusion Team July 3, 2002 05:48 AM UTC

If you look at the second solution (suggested by Jacob Grass) in the FAQ referenced below, you will see how you can drag a form around by mousing down on it. This is done by handling some mouse events. In this code, if you replace the Form replace your label, you would drag the label. So, one solution would be to derive a DragLabel class, and put this code into that class. Instead handling the events at the form level, you would override the virtual OnMouseDown, OnMouseUp and OnMouseMove and place the code there. You would also want to stop the moving if the user tried to drag outside the panel (the label's Parent).Then any time you need a drag label, you would use your derived label. George Shepherd's Windows Forms FAQ contains an entry entitled: How can I drag a window if it doesn’t have a title bar or border? Check it out at: http://www.syncfusion.com/faq/winforms/search/699.asp


RA Ray July 3, 2002 11:54 AM UTC

Hi Clay, Thanks for the link, just got one more question. If I need to drag an item from the list box to the panel, which event will capture the location of the drop point. I can use the panel mouse move event to capture the location inside the panel but it won't work when I try to drag an item into the panel. Any idea? Thanks.

Loader.
Up arrow icon