Please see my comment to the question.
The problem is quite apparent. The code is incorrect, because you do rendering on click events. The drawing happens, but it does not persist. You should do all the rendering in your handler of the event
, or in the overridden
method. Use only the instance of
obtained from event arguments.
You gradient is done correctly, shapes are not. Your handler of the mouse event handlers should only modify some data (store it in a control class, for example), and trigger re-rendering by calling
Please see my past answers:
Drawing Lines between mdi child forms
capture the drawing on a panel
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))
How to speed up my vb.net application?
I'm not saying that you never should do drawing in mouse event handlers. Sometimes you can, but this is an advanced technique. You should understand that the rendered drawing will not persist unless you reproduce the drawing in
. My past answer explaining how
works should explain it for your.