Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create a user defined controls with drag and drop

Posted on 2013-10-30
2
Medium Priority
?
309 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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview

927 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