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
Paint
, or in the overridden
OnPaint
method. Use only the instance of
Graphics
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
Control.Invalidate
.
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?[
^].
[EDIT]
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
OnPaint
. My past answer explaining how
WM_PAINT
works should explain it for your.
—SA