Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding Drag & Drop for Target Coordinates?

Status
Not open for further replies.
Feb 7, 2001
4
US
Hello! I'm trying to implement a simple drag and drop of an image to a PictureBox. I've got the drag modes, etc. set. This is a non-OLE drop. My Q is, can I use a coordinate zone to specify the picturebox?

ie:

if not within picturebox coords then
(bad drop)
else
(good drop)

Problem is, I don't know where to put this code. I can't/don't want to call the (bad drop) function from DragDrop(Source,X,Y) for every object and control on the form!

Any thoughts?
 
When you drag and drop, the code executes inside the DragDrop event for the control you dropped on, and the "Source" is the item that was dropped into the control.

Since you are already assured that the drop took place inside the picturebox if that event fires, then you don't need to test for a "good" drop. ( You are only checking for a "bad" drop )

If it's not within the picturebox co-ordinates, then the drop event won't fire for that control. It may fire for other objects ( depending on where they did drop the item ) but if you have no code in those events, then nothing will happen.

If you want something to happen if they did not drop it in the right place, then that's a bit more complicated. Since you are not using the OLEDrag, you have to resort to checking all of the other places they could have possibly dropped the item in question.

Robert
 
That all makes perfect sense, I should have been a little more specific.

Form_DragOver sets Source.Visible to False, giving the appearance of dragging the actual picture. On a bad drop, I need a way to set that property back to visible(thus the bad drop handling function).

So, the only workaround here is with OLEDrag?
 
Sorry that it took so long to get back to you.

The two workarounds are:

Put code in each dragdrop event for each possible place they could have dropped it. A control array would simplify things here, but you may be so far into the project that you don't want to do this.

The other is to use the OLE drag. The problem here is that the Form's Dragover event for OLE does not give you the source, so you can't make the control invisible in that event.

You can make it invisible in it's OLEStartDrag event. ( and make it visible again in the CompleteDrag event, depending on if the drag weas successful or not ). Again, a control array can make this easier.

For what you want to do, I'd say to use the OLE drag functions.

HTH

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top