|
|
Drawing On A Form
Create a C#, Windows Application Project.
Choose an appropriate name for your Form. I changed the name Form1, to FDraw. In
the Properties window for your Form, set the BackColor. I use White for my drawing
surface.
Use the Object Browser, to see what methods in your base class can be overridden.
In the View menu, go to Other Windows and select Object Browser. Look for the OnPaint
function in the Form class as shown in the screen shot.

Now that we know there is an OnPaint function, and what the parameters are, add
code to override the OnPaint function in your Form class and try it out.
protected override void OnPaint( PaintEventArgs pe )
{
Graphics g = pe.Graphics;
Pen myPen = new Pen( Color.Blue, 2 );
g.DrawLine( myPen, 10, 10, 210, 210 );
g.DrawLine( myPen, 10, 210, 210, 10 );
g.DrawEllipse( myPen, 50, 50, 200, 100 );
myPen.Dispose();
}
Here is a screen shot showing the results.

For more information, look in the .NET Framework SDK documentation, in the .NET
Framework Reference section. Look for the Graphics class in the System.Drawing namespace.
Look for the Form class in the System.Windows.Forms namespace.
wburris at telusplanet dot net |
|