-
Graphics Editor
I am trying to create a simple graphics editor where a user can draw lines with the mouse in a picture box already containing a background. The idea is to allow the user to create a network over a map.
I am using the VB line object to create the lines the user draws.
But the problem is to edit the lines drawn by the user. As the Line object does not have any Click or MouseMove method, I am unable to allow users to edit them. I want the users to click on the endpoint of the line and move it to a new location to stretch or reduce the length.
Can someone please help?
-
well there is different ways to do things like this. One easy way would be:
do it all in a picture box. You are going to take its mouse move event
in the mousemove event first check if a button is pressed if so (and if it's the first time it is pressed down, meaning it has not been held down...you check this over a global boolean) you put a for each loop for all the lines and check if one of their endpoints is under the mouse. You need to add some tolerance here since it is kind of hard to hit a line that accurate. Also to make things easier set the pictureboxes scalemode to Pixel.
now for the editing... early you had to check if the mouse is down, but has not been held, there you decide which line to take. Now if you already selected a line and the user still holds the button down you just the set selected point according to the x and y value you are given by the mousemove event.
I hope this helps, if you need more info post again.
-
well I talked about different ways to do it earlier and than I only put one way so here we go.
Since it would be nice to give the user a clue where to click for a line you could move small buttons to the end of each line (maybe if the user enabled some editing mode) using the "for ... each" again. Now you would have a click event and all, so you would just put in the moving as described above.
-
hi
thanx for ur suggestions with i was able to do it. thanx again.
however i still have a problem. i'm trying to draw the lines in different styles, like dashed, continuous etc. but when the style is dashed, the line width remains 1 and hence appears thin. is there a workout for it?
-
Sorry, but VB doesn't draw dashed or dotted lines with a width greater than 1. Neither does Windows I think :)
So if you really want that, you can write the lines routine yourself... but in my opinion it's not worth it for a tiny effect like that ;)