Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   Code Library (http://www.xtremevbtalk.com/code-library/)
-   -   Dragging and Dropping with VB.NET (http://www.xtremevbtalk.com/code-library/164308-dragging-dropping-vb-net.html)

Iceplug 04-30-2004 10:33 AM

Dragging and Dropping with VB.NET
1 Attachment(s)
Dragging and Dropping controls on a form!
Check out the attached solution:

Main points:
Set your destination's .AllowDrop to True
In your source's Mousedown, call its .DoDragDrop event.
In the destination's .DragEnter event, check for .GetDataPresent and set the e.Effect.
In the .DragDrop event, it is done!

In the attached solution:
Throw an ant into a timeless vortex! :)

Edit: You also might notice that the .DoDragDrop event pauses execution.

Iceplug 05-03-2004 05:56 PM

DragDrop with Movement
1 Attachment(s)
Here's an example that supports dragging and dropping that actually moves the shapes to where you drag them...

the first method assigning e.X and e.Y in the DragDrop to the picturebox location... well, it "works", but it's wrong.

A more proper method would be to turn the e.X and e.Y into a Point and then use the form's .PointToClient method to get the right location.

Check out the attachment. :)

Iceplug 05-11-2004 01:20 PM

Three more examples
3 Attachment(s)
Here are three examples of drag dropping.
If you are going to peruse them... go through them in order.
It's more fun that way.

This illustrates how to move the drag dropped picturebox to the destination with the most realistic drag drop... you take the point where the user clicked on the image, and when they drop the image, you move the image with respect to this point, so that the image appears under the mouse at the same position it was when they clicked on it.

This shows how to drag multiple objects onto multiple drag drop targets (and I use the DragLeave event). I also create several pictureboxes at run time so it looks neat and it looks like a control array.

This one shows you how you can use the effects to make a Copy or a Move effect depending on if the user is pressing down the Ctrl button. If the control button is pressed, you get the copy effect and see the copy mouse cursor... if not, then you get the regular move.

Have fun... more examples coming soon. :)

All times are GMT -6. The time now is 03:31 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.