response to drag & drop

jerryfchui
06-26-2001, 11:02 PM
Today my daughter (a high schoold student) wants to add a fancy bit to its VB programming project/exercise. The system must wait until an operator has dragged an apple onto a CAT's month, for example, before it start loading the form with the main menu for her work.

How do I make vb to response to the event of a drag and drop action? I couldn't answer that, despite I have programmed using VBA (with Access, Excel etc.), VB, Java, C, Web programming, etc. for years. Most applications I wrote involve database access and kind of client/server applications.

It seems it is a subject of game programming, something I do not want to get deeply involved at this stage. Can somebody tell me a quick-&-dirty solution? Or let me know the key subjects of some tutorials I must read now, if I simply want to achieve the above.

Ad1
06-27-2001, 02:27 AM
look at the dragdrop event of the cat picturebox, it should look like this
<pre>Private Sub picBox_DragDrop(Source As Control, X As Single, Y As Single)

End Sub</pre>source is the control that is being dropped and X and Y are the coordinates of its position over the picbox

so if you figure out the coordinates of the cats mouth, say the left edge is 500, the right edge 1000, top 300, bottom 700 then you could put the following code into the dragdrop event
<pre>if X=&gt;500 and x=&lt;1000 and Y=&gt;300 and Y=&lt;700 then
source.visible=false 'make apple dissapear
subLoadForm
endif</pre>then put your code from the Form_Load event into a sub called subLoadForm which will only be fired once the apple is dropped into the cats mouth

alternatively you could put your cat and apple on a seperate form and replace the line subLoadForm with <pre>frmMain.show
Me.Hide</pre>

BillSoo
06-27-2001, 02:32 AM
There are 2 basic ways to handle this....automatic and manual. Automatic is easier but manual is a bit more flexible. I'll describe automatic....

1) Suppose you have an object you want to drag-drop. Let's assume it's a picturebox. Set it's dragmode to automatic.
2) In the target object, ie. another picturebox, you have a dragdrop event. This event has a parameter called Source.

When you drag the first picturebox and drop it in the second, the drag drop event is fired and source refers to the dropped object. You can use this reference to check to see if it is the proper kind of object, and you can move the source object in the drag drop event of the target.


"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum