Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a line drawn and want to detect if any picturebox is being placed on it.
Posted

Someone can correct me if I'm wrong, but it's going to be complicated, I think.

First, I assume you're using the LineShape from within the Visual Basic PowerPacks? (and yes, I know this is a C# ?)

Even if you're not and just drawing a line on the form programmatically, you're going to have to use either the form's drag events, or the container that it is drawn on.

Assuming you already have a PictureBox being dragged, first hook the Form's DragEnter and DragOver events and in that code, first, check if there is a PictureBox present
C#
if (e.Data.GetDataPresent(typeof(PictureBox))


then you have to check if it's over the line. If it's a LineShape from the VB PowerPacks, you can do a HitTest
C#
if (lineShape1.HitTest(e.x,e.y))


Then, you set e.Effect to what effect you want. Then, you handle the DragDrop in the form and add the PictureBox to the line that the DragDrop happened over.
 
Share this answer
 
To add to the other answer, if you're going to do something this complex, it becomes a lot easier ( but still complex ) if you ditch the picturebox and just draw the picture in your paint event. This gives you a lot more control over what is going on.
 
Share this answer
 
How can i do a line test? Could you provide me with some codes?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900