Hey, I need to do my drawing over a panel in C# but without placing my drawing code inside “panel1_Paint”, how can I do that ??
BTW, I’m using WinForms.
Update : I forgot to make something clear, I need not to place my drawing code inside paint handler, because I need to start drawing depending on buttons’ events.
Usually you do all your drawings in the paint event handler. If you want to do any update (if a user clicks on the panel for example) you have to defer that action: you store the required data (coordinates where the user clicked) and force a redraw of the control. This causes the paint event to be fired, where you can then draw things you stored before.
Another way would be (if you really want to draw outside of the ‘panel1_Paint’ event handler) to draw inside a buffer image, and copy the image to the controls graphics object in the paint event handler.
Update:
An example:
Now the drawn images wont be lost, even after a redraw of the control, because it only draws out the buffer (the image, saved in the memory). Additionally you can draw things anytime a event occurs, by simply drawing into the buffer.