C # drawing (1)

Source: Internet
Author: User

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;
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.