Solved

Create a user defined controls with drag and drop

Posted on 2013-10-30
2
284 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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