Drag events on custom controls

andyh20

Member
Joined
Aug 4, 2009
Messages
11
Programming Experience
5-10
I've created a custom control that consists of a number of panels, buttons and labels. I'm trying to enable dragging and dropping onto this control at runtime. it's almost working but it seems that the drag events are only fired when the cursor is in the very small area between the boundary of my control, and the panel that contains all the other controls in my custom control.

I've tried setting the allowdrop property of all the controls that make up the control to True, and needless to say the custom control's allowdrop property is also set to True.

How do I get the bulk of the control to recognise the dragging?

Thanks,
Andrew
 
You probably have the dragenter/over/leave/drop events wired to only the UC and not the other panels, add them to the same events and your good.
 
Thanks for the advice, but I'm not entirely sure what you mean by 'add them to the same events'.

I'm coming from a VB6 background so a lot of the event handling is new to me. Do I need to raise a drag drop event out of the custom control?
Thanks
 
Where you create the UC you can add events to them with an addhandler statement
VB.NET:
Dim UC As New Usercontrol
Addhandler UC.panel1.DragOver, AddressOf MyDragOver '<-name of sub handling the event
...
Private Sub MyDragOver(Byval sender As Object, Byval e As DragEventArgs) '<-same event signature
'your dragover code
End Sub
As you can see there is no Handles clause at the end cause we used the addhandler statement. Do the same for all the drag events you use - dragenter/dragleave etc... More than 1 panel can use this dragover event.
 
Thanks

Thanks again. I can't see my panels outside of my user control though to add a handler as you suggest.

Should I be doing something inside the user control code to 'pass up' the drag events from the panels up to user control event level?

Sorry for dragging this out so.
Andrew
 
Thanks again. I can't see my panels outside of my user control though to add a handler as you suggest.
I don't understand this line. Can you elaborate?
 
Sorry, and thanks again for your continued assistance.

You suggested the line:
Addhandler UC.panel1.DragOver, AddressOf MyDragOver

Obviously changing UC for my user control's and panel's name, I get a compile error that the panel has friend scope and so isn't accessible outside the control.

I can't help thinking that I shoudl be able to do something to encapsulate all this within the user control itself rather than requiring every implementation of the control to link the panel events to the user control events. Any thoughts?
 
This suggests that you dropped the control onto the form right? If so you can still access the panel, but you have to use the <control.name>.panel.DragOver and place this addhandler in the form load event. Let me know if that helps.
 
Back
Top