Override the method
Form.OnPaint
. In this method, use the instance of
System.Drawing.Graphics
passed to you via the event argument parameters, and paint on the form using its method
System.Drawing.Graphics.FillRectangle
. For a brush, use a gradient brush
System.Drawing.Drawing2D.LinearGradientBrush
.
Please see:
http://msdn.microsoft.com/en-us/library/yysstebh.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.lineargradientbrush.aspx[
^].
Don't forget to dispose the objects which implement
System.IDisposable
. The best way of doing it and guarantee that it happens even if an exception is thrown, is using the
using
statement, which acts identically to the try-finally block:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[
^],
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.100%29.aspx[
^].
You may face some flicker. You can eliminate it using double buffering for the form (or other control) where you do your custom rendering:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx[
^].
Best wishes and wake-ups… :-)
—SA