// Implementation function: draw a line with the created PEN.
// (This example uses using to create a Pen. The advantage is that when the object (pen) is out of scope, the using structure automatically calls Dispose () to delete the PEN.
// If you use other methods to create a Drawing Object (usually resources are charged), you must explicitly call Dispose (), for example:
// "Graphics g = this. CreateGraphics ();
//........
//........
// G. Dispose ();"
// Key points:
// Create a Pen. The color and Width of the Pen are used to obtain the height and Width of the customer area.
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Namespace myDrawPanA
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Protected override void OnPaint (PaintEventArgs e)
{
// Base. OnPaint (e );
Graphics g = e. Graphics;
Using (Pen myPen = new Pen (Color. Red, 1 ))
{
If (ClientRectangle. Height/10> 0)
{
For (int y = 0; y <ClientRectangle. Height; y + = ClientRectangle. Height/10)
{
G. DrawLine (myPen, new Point (0, 0), new Point (ClientRectangle. Width, y ));
}
}
}
}
}
}