Link to home
Start Free TrialLog in
Avatar of mortar
mortar

asked on

Drag'n'drop code - Similar to card game

Hi i'm trying to assemble a program and i've come across a need for the code similar to in the card game Solitaire for instance.. I need to be able to drag and drop an object (preferably with a picture) to a destination and be able to pull it off the object again.  I'm not quite so sure where to start, any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mortar
mortar

ASKER

Very awesome code.  I had a quick look into the first one but preferred the code you posted here as I wanted the 'picture drag' as well, not just the boxed outline.  I added pictures in and it does exactly what I need although the double click function didn't work properly for me, I had to add the pictures in design mode?

I'm still getting used to the new version of VB.Net as I was using VB6 before, they've changed the shortcut key to the step-into function from F8 to F11, and the feature itself also doesn't seem to function the way i'm used to..  i.e. in VB6 if you stepped through your code then hovered over a 'mouse over' event, it would pause and drop back into the code design window to show you what event/code has taken place.  Although if I step into the code in this project, nothing happens when I double click the above picture boxes or drag them around the form to tell me what code is being processed in the background..

Ultimately I want to be able to tell which picture has been put in which box.. I've also noticed you can't drop more then one picture on a box at any one time which is perfect for what I want although I noticed although additional pictures cannot be 'snapped' as such they can be placed anywhere on or around the form, getting in the way of the other pictures.

Point increased to 400 ;)
That's weird about the double clicking not working for you.  Did you create a completely new project and add ALL of the code I posted over the default code for the form?

You can determine which picture was put into which box by using the tag property of the pbs in the targetPBs arraylist.  If a picture is currently positioned on a target pb then that pbs tag property will have a reference to the corresponding picture...otherwise it will have Nothing to indicate it is empty.

As a side note, you can place ANYTHING in the tag property so you could create a more complex class to track more things at once and then place an instance of that class into the tag propety instead of a single reference to a pb.

It shouldn't be too difficult to make a snapping feature for the open area of the form.  Describe to me a little about you want it to work and perhaps I can give more suggestions or code.

~IM
Avatar of mortar

ASKER

Sorry my bad..

This message came up:
----------------
The project location is not fully trusted by the .NET runtime. This is usually because it is either a network share or pmapped to a network share not on the local machine. If the output path is under the project location, your code will not execute as fully trusted and you may receive unexpected security exceptions. Click OK to ignore and continue. Click CANCEL to choose a different project location.
----------------

It works ok if I save it on the local machine.  I'm running gentoo with an emulated Windows XP installation, so i'd prefer to save it to a 'network share' if possible.. Is there anyway to add it as a trusted location?
Avatar of mortar

ASKER

Ok basically the program that I want to create is the one described here but i've had more ideas since..

https://www.experts-exchange.com/questions/21356823/Volleyball-Game-Times-VB-Program.html

As described in the link, i'm trying to make a program to schedule game times for a volleyball centre and I was just trying to work out the easiest way to interface it..

From what you've given me here, I thought of making pictures of all the team names, and having them in a source pool, and being able to dragging 2 teams to a destination box (or 2 different boxes on the same court,time etc) to signify that they were playing each other.