Drag and drop controls into a usercontrols?
-
I have created a usercontrol in vb.net, but i want the ability to add other controls to this using the form designer? This already happens in visual studio, for example when you drop a panel on the form and then drag and drop another control, button, panel, anything into that panel in then adds it to the control. how can i add this function to my control?:doh: e.g
Private Sub DragDropControl_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop 'gets the control End Sub
Private Sub DragDropControl_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter 'reads the data and check weather this type of control can be dropped End Sub
thanx -
I have created a usercontrol in vb.net, but i want the ability to add other controls to this using the form designer? This already happens in visual studio, for example when you drop a panel on the form and then drag and drop another control, button, panel, anything into that panel in then adds it to the control. how can i add this function to my control?:doh: e.g
Private Sub DragDropControl_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop 'gets the control End Sub
Private Sub DragDropControl_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter 'reads the data and check weather this type of control can be dropped End Sub
thanxSo, you want to drag a control from somewhere on your form, onto your usercontrol, at design time? Do you just want it to be visible there, or do you want it to be part of the control? Normally, the drag an drop features for controls handle data from one control to another. What you want to do can probably be done, but it may take some work. Roy.
-
So, you want to drag a control from somewhere on your form, onto your usercontrol, at design time? Do you just want it to be visible there, or do you want it to be part of the control? Normally, the drag an drop features for controls handle data from one control to another. What you want to do can probably be done, but it may take some work. Roy.
-
Basically my usercontrol is like a toolbar control that you would move other controls onto, but like you say Roy yes the controls added would have to then become attached or added to the main base control.
OK. What you will need to do is, as the control is dropped on your user control, identify what type of control it is. I assume that you want this control to be persistant (i.e. still there when you restart your app later). If so, you need to store a list of controls to be populated on your user control. You could store the list in an XML file, or in the registry. Finally, you need to dynamically create the controls; both at startup, and when a new control is added. Remember that you are not actually dropping a control on your usercontrol, you are identifying the type of control. Sorry is this is kind of vague. I have not actually done this. But this is how I would try it. Hope this helps. Roy.