Solved

Create a user defined controls with drag and drop

Posted on 2013-10-30
2
278 Views
Last Modified: 2013-10-30
I am writing a small control which will be an instanciated many times in a list, yet another user control.  I wish to drag and drop one or more controls from that list into another control.  Is there any reliable reference material that would help me move forward with this.  

I have done drag and drop with standard controls but this seems slightly different and any guidance or reading material would be of great help.
0
Comment
Question by:Alyanto
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39611645
I assume you mean at run-time?

Long story, short, it's not really different than any other control.  You may need to initiate the drag from within the child controls, however.  For instance, if there is a Label in the UserControl then clicking down and dragging on it would fire events in the Label instead of the UserControl itself.  You'll have to take that into account in your code.

But basically you just do:
	Public Class UserControl1

		Private Sub UserControl1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
			If e.Button = Windows.Forms.MouseButtons.Left Then
				Me.DoDragDrop(Me, DragDropEffects.All)
			End If
		End Sub

	End Class

Open in new window


Then handle the normal Drag/Drop events in the receiving control and move the UserControl to the new container by adding it to the Controls() collection.
0
 
LVL 1

Author Closing Comment

by:Alyanto
ID: 39611740
Nice one,
 

Many thanks

/Aly
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now