Usually you do all your drawings in a paint event handler. If you want to make some kind of update (if the user clicks on the panel, for example), you should postpone this action: you store the necessary data (the coordinates where the user clicked), and force the control to be redrawn. This will cause the drawing event to fire, and then you can draw the things you saved before.
Another way would be (if you really want to draw outside the panel1_Paint event handler) to draw inside the buffer image and copy the image to the graphic control object in the paint event handler.
Update:
Example:
public class Form1 : Form { private Bitmap buffer; public Form1() { InitializeComponent();
Now, inverse images will not be lost even after redrawing the control, since it pulls out a buffer (an image stored in memory). In addition, you can draw things at any time when an event occurs, simply pasting it into the buffer.
Philip daubmeier
source share