|Use the Paint handler, it is the only place where drawing ever should occur.
CreateGraphics, it is an expensive operation. The Paint handler gives its
Graphics for free, see the
PaintEventArgs that comes with it.
For all those small but disposable objects (Pens, Brushes, Fonts, ...) consider NOT creating them all the time by either:
- using the pre-existing ones, e.g.
(and since you didn't create those, you are not supposed to dispose of them either);
- creating your own, possibly more specialized ones (e.g. a thicker Pen) but then create them only once and keep them alive in class variables; when doing so, there is no need to dispose of them when your program exits.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...