GDI + is used for drawing, stock software, ECG, etc. are GDI painting, GDI is not. NET technology, he is a separate technology
private void Form1_Load (object sender, EventArgs e)
{
Paint requires a pen, color a piece of paper, two dots, draw a straight line object
The paper is the form, and the object that draws the line is the GDI object
}
private void Button1_Click (object sender, EventArgs e)
{
//Create GDI objects ;
Graphics g = this. CreateGraphics ();//Create Object//new Graphics () through this current form;
//Create a Brush object
Pen pen = new Pen (brushes.yellowgreen);
//Create two points
point p1 = new Point (30, 50);
Point p2 = new Point (250, 250);
g.drawline (pen, p1, p2);
When we move the form from one place to another, the operating system wipes out the original and re-draws a new one;
When we draw a line from the form, the form will be redrawn by the operating system, but the line will not be redrawn again by the operation, so the line disappears
}
int i = 0;
private void Form1_paint (object sender, PaintEventArgs e)//the event that is executed when the form is redrawn;
{
i++;
Label1. Text = i.ToString (); The number of times the record was redrawn;
Create GDI objects;
Graphics g = this. CreateGraphics ();//Create Object//new Graphics () through this current form;
Create a Brush object
Pen pen = new Pen (brushes.yellowgreen);
Create two points
Point P1 = new Point (30, 50);
Point P2 = new Point (250, 250);
G.drawline (pen, p1, p2);
}
To see the parameters of the method overload, the method name is followed by a bracket, pressing the upper and lower arrow keys;
private void button2_click (object sender, EventArgs e)
{
Graphics g = this. CreateGraphics ();
Pen pen = new Pen (brushes.red);
Size size = new size (80,80);
Rectangle rec = new Rectangle (new Point (50,50 ), size);
g.drawrectangle (pen, rec);
}
private void Button3_Click (object sender, EventArgs e)
{
Graphics g = this. CreateGraphics ();
Pen pen = new Pen (brushes.blue);
Size size = new size (180,180);
Rectangle rec = new Rectangle (new Point (150,150), size);
G.drawpie (pen, REC, 60, 60);
}
private void Button4_Click (object sender, EventArgs e)
{
Graphics g = this. CreateGraphics ();
g.DrawString ("Beautiful and Lovely Ball", New Font ("Arial", "Fontstyle.underline"), Brushes.gold, New Point (300, 300));
}
The image inside the system is the bitmap by default;
--------Drawing Verification Code;
private void PictureBox1_Click (object sender, EventArgs e)
{
Random r = new Random ();
string str = NULL;
for (int i = 0; i < 5; i++)
{
int rnum = r.next (0, 10);
str + = Rnum;
}
Create GDI objects;
Bitmap bmp = new Bitmap (120,40);
Graphics g = graphics.fromimage (BMP); Draw on BMP
for (int i = 0; i < 5; i++)
{
string[] Font = {"Microsoft Jas Black", "Arial", "Black Body", "Official script", "imitation"};
color[] color = {Color.red,color.yellow,color.blue,color.green,color.pink,color.purple,color.black, Color.chocolate};
New SolidBrush monochrome Brush, parameter color, the coordinates of the last parameter point cannot be given randomly, random will overlap
Point P = new Point (i*15,0); This point coordinate is not relative to the form, but bitmap;
g.DrawString (Str[i]. ToString (), New Font (Font[r.next (0,5)],30,fontstyle.bold), New SolidBrush (Color[r.next (0,8)]), p);
}
//To draw interference lines to the image;
for (int i = 0; i < i++)
& nbsp; {
//The coordinates of a straight point must be in BMP
point p1 = new Point (R.next (0,bmp. Width), R.next (0,bmp. Height));
Point p2 = new Point (R.next (0,bmp. Width), R.next (0,bmp. Height));
G.drawline (new Pen (Brushes.green), P1,P2);
}
The pigment particles are not GDI, but directly set the color of BMP pixels;
for (int i = 0; i <; i++)
{
The coordinates of the point must be inside the BMP.
Point P = new Point (R.next (0,bmp). Width), R.next (0,bmp. Height));
Specify the pixel color in the picture
Bmp. SetPixel (p.x, P.Y, Color.darkolivegreen);
}
Mosaic the picture into the PictureBox,
pictureBox1.Image = BMP;
}
The first step is to generate a random number; the second step is to draw the string, the third line, the fourth step to draw points;
15-03-16 GUID Drawing Verification Code