This is because you are doing it wrong. Actually, this is a pretty common mistake.
The rendering of graphics persists only if you perform it on each
Windows message. For this purpose, you should handle the event
, or, better yet, override the virtual method
in your derived control of form class. The message
will be triggered each time some area of the control needs re-painting, for example, when a part of a control was hidden under some other window. Normally, you do all the changes in graphics in some data, and when you change the data (with your mouse events or by any other action), you need to force sending the message. This is done via one of the
methods. Sometimes, it's good to use the method
with parameters (
), to invalidate just the part of the scene, which can help you to improve performance.
Also, you should not create an instance of
(please see my comment to the question). You should use the instance passed to your handler of the event
or the virtual method
as the event parameter.
Please see my past answers to related questions:Drawing Lines between mdi child forms
],capture the drawing on a panel
],What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))