11.7. Practice
Now that we have had an overview of the main functionality provided by the System.Drawing namespace and secondary namespaces, such as System.Drawing. Drawing2D and System.Drawing.Imaging, let’s have some examples that illustrate how to use this functionality.
OnPaint method
To be able to use graphical functions, we need to get a reference to a graphics object – the Graphics class, which provides the device context for drawing. We can do this in the OnPaint event handler, which is called every time the form must be redrawn, such as, when it is created, resized, or moved.
The OnPaint event handler receives a PaintEventArgs object supplied by the system. This object contains various members that specify the Graphics object used ...
Get A Programmer's Guide to .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.