Click to See Complete Forum and Search --> : Drawing Line, then Updating?


code?
April 5th, 2009, 10:18 PM
Alright, so if I have a place to draw lines on a form, with a pen and a graphics. How can I keep track of them, so I can update their individual positions if I need to.

There will be a drawing canvas, as well as a list of the drawn lines, and their points, where you can edit the locations and the lines will update.

Would an array do it? Or what? Can I even change the individual Xs and Ys of the lines?

JonnyPoet
April 6th, 2009, 04:41 PM
Alright, so if I have a place to draw lines on a form, with a pen and a graphics. How can I keep track of them, so I can update their individual positions if I need to.

There will be a drawing canvas, as well as a list of the drawn lines, and their points, where you can edit the locations and the lines will update.

Would an array do it? Or what? Can I even change the individual Xs and Ys of the lines?This depends on what and how it is drawn. If you are drawing simple graphical objects like a circle, a line a rectangle, text, then you can store each item in a list starting every time when the line begins and when it ends.
for example for a straight line you simple store the start and the endpoint thickness, color and if its a full line, a dotted line...
All this can be packed into a drawing item class you can design and store them cycle by cycle in a list.
This way you can undo or redo by simple adding or removing items from the LIFO list (LIFO = Last in First out) maybe google for 'bizdraw' which is a free source code program on codeproject
It has some errors but basically its easy to be repaired and there you can study how this works

code?
April 8th, 2009, 01:46 AM
Oh ok, I was using this.

http://msdn.microsoft.com/en-us/library/aa287522(VS.71).aspx

JonnyPoet
April 13th, 2009, 02:31 PM
Oh ok, I was using this.

http://msdn.microsoft.com/en-us/library/aa287522(VS.71).aspxes OK, but if you want to be able to use Undo then you need to know what was drawn and in which order it was drawn.

look at this
http://www.codeproject.com/KB/cs/BizDraw__for_net.aspx

It does what you expected.
Basically the point is if you want to change positions of lines and you simple redraw the line to the already drawn screen, then the old line is still visible on screen. If you draw different things one after the other in the same draw event then you can change positions of start and endpoints and redrawing the whole picture and it will be changed. But in both cases you need to store the values of each line with startpoint, endpoint, thickness, color...
So do a line class and store all whats needed for a single line.
All changes are done to this class and each single line is an instance of this line class e.g named 'LineData'. You save all of them in a List<LineData>
If you are drawing you simple run through this list and draw each of the items. Such simple