Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to draw line between two points, using mouse up and mouse move ,mouse down.

What I have tried:

if click the mouse down and get the point, to add list ,same as to do mouse up. finally
using the mouse move points to draw line. but here want happen first two points will draw line ,but upcoming point did not draw the line.
and also continuously i want to draw lines on last point to new mouse click point.if i move the mouse anywhere in picture box that line will comes to moving position also at last i click the mouse up to finish the line drawing.
Posted
Updated 26-Mar-18 3:22am
Comments
OriginalGriff 26-Mar-18 6:22am    
What have you tried?
Where are you stuck?
What help do you need?

You didn't say what you were drawing on/in, but what I did in a similar situation was to keep a list of the Points clicked (MouseDown) and draw the lines, redrawing the entire canvas every time the Mouse Up event occurred. It happens quickly enough that you don't notice the redrawing.

Using Polyline.Points, adding new points to it with each click would have the same effect, and might be easier than drawing individual lines.
 
Share this answer
 
You seem to be having a problem with what I'll loosely call a flag.

You need to tell you application when the mouse is first clicked and store its location.
Then, you need to tell your application when the mouse was clicked at the second location so you can call the line-drawing function.

At this point, what you want becomes unclear. Do you want to connect each new mouse click to the last one so you draw a series of lines connected to one another, or do you want to make new lines that are generally not connected to one another.

And that is where the flag comes in. You need to manage what your program's state is in. In the first case, all you'd need to do is keep track of the most recent click, and then, on a new click, draw the line and save the new point. In the latter case, you need to set a starting point, and then, when you click the ending point and draw the line, you need to clear the data. Or, have a flag that tells the system if it's waiting for the first or second click of the pair.

OK - now, use your debugger and see the state of your application as you step through it. Is the reason to draw more lines re-enabled? Or perhaps, you keep drawing the same line, over and over, making it look like nothings happening.

You will need to figure this out - and the learning will make you a better programmer.

 
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