Solved

Create a user defined controls with drag and drop

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

Author Closing Comment

by:Alyanto
ID: 39611740
Nice one,
 

Many thanks

/Aly
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

12 Experts available now in Live!

Get 1:1 Help Now