protected override void onpaint (painteventargs paintevnt)
{< br> // obtain the canvas
graphics GFX = paintevnt. graphics;
// build a paint brush
pen mypen = new pen (color. black);
// draw line
for (INT I = 20; I <250; I = I + 10)
{< br> GFX. drawline (mypen, 20, I, 270, I);
}< BR >}
Draw a square vertical:
Protected override void onpaint (painteventargs paintevnt)
{
// Get the graphics object
Graphics GFX = paintevnt. graphics;
// Create a new pen that we shall use for drawing the line
Pen mypen = new pen (color. Black );
// Loop and create a horizontal line 10 pixels below the last one
For (INT I = 20; I <= 250; I = I + 10)
{
GFX. drawline (mypen, 20, I, 270, I );
}
// Loop and create a vertical line 10 pixels next to the last one
For (INT x = 20; x <280; X = x + 10)
{
GFX. drawline (mypen, X, 20, X, 250 );
}
}
Draw a box:
Protected override void onpaint (painteventargs paintevnt)
{
// Get the graphics object
Graphics GFX = paintevnt. graphics;
// Create a new pen that we shall use for drawing the line
Pen mypen = new pen (color. Black );
// Loop until the coordinates reach 250 (the lower right corner of the form)
For (INT I = 0; I <250; I = I + 50)
{
// Draw a 50x50 pixels rectangle
GFX. drawrectangle (mypen, I, I, 50, 50 );
}
}
Cycle, painting gradient
Protected override void onpaint (painteventargs paintevnt)
{
// Get the graphics object
Graphics GFX = paintevnt. graphics;
Int X1 = 0;
Int Y1 = 0;
// Loop trough the 255 values red can have
For (INT I = 0; I <= 255; I ++)
{
// Specify the paint brush color
Color brushcolor = color. fromargb (I, 0, 0 );
// The solid paint brush is used to draw a solid rectangle.
Solidbrush mybrush = new solidbrush (brushcolor );
// Draw
GFX. fillrectangle (mybrush, X1, Y1, 10, 10 );
// Draw a rectangle.
X1 = X1 + 10;
// When a row ends, draw the next row
If (x1% 290) = 0)
{
Y1 = Y1 + 10;
X1 = 0;
}
}
For (INT I = 0; I <= 255; I ++)
{
Color brushcolor = color. fromargb (0, I, 0 );
Solidbrush mybrush = new solidbrush (brushcolor );
GFX. fillrectangle (mybrush, X1, Y1, 10, 10 );
X1 = X1 + 10;
If (x1% 290) = 0)
{
Y1 = Y1 + 10;
X1 = 0;
}
}
For (INT I = 0; I <= 255; I ++)
{
Color brushcolor = color. fromargb (0, 0, I );
Solidbrush mybrush = new solidbrush (brushcolor );
GFX. fillrectangle (mybrush, X1, Y1, 10, 10 );
X1 = X1 + 10;
If (x1% 290) = 0)
{
Y1 = Y1 + 10;
X1 = 0;
}
}
}