Im using System.Drawing.Graphics graphicsObj for drawing objects on System.Windows.Forms.Panel. What is wise method to store informations about old drawings? To remove last drawing during MouseMove event?
Do i have to remember Pen settings and cords?
Thanks 🙂
// edit. I think my question is not clear. I have a Panel. I treat it like a container for drawing.
I can draw multiple lines, circles, rectangles.
Every time i press the mouse (MouseDown), im want to start drawing new object. When i move mouse (MouseMove), object currently drawed has to change (for example line, like in paint). When i release the mouse (MouseUp), i want object i drawed to became constant.
Now, i tried to invoke graphicsObj.Clear(); method on MouseMove event, but it clears all drawed objects.
So i deduced, that i have to store informations about old drawed objects. And now, i have to make lists (vectors or so) and store informations about that objects? Or there is a method to avoid it?
You should handle all painting in the
Panel‘sPaintevent, that is exactly what it’s there for.The
Paintevent gives you in itsPaintEventArgstheGraphicsobject you should use. This will make sure your instructions are painted on every refresh, not just once.If you are deriving from
Panel, override theOnPaintmethod instead.Edit after original question has been expanded:
You should separate the logic of storing the data from the logic of displaying your data. The
Graphicsobject’s purpose is to display existing data, not to store data.I think making
Lists or other collection of the objects you are drawing is the best solution.You will also need flags to handle all the logic of what is a “live” object, etc.