1. Define the canvas
Graphics G = paintevnt. graphics; // drawing the canvas Member of the event
Graphics G = This. creategraphics (); // or directly generate. This can be form1, picturebox
Graphics G = graphics. fromhwnd (hwnd); // generate a window handle. Where: intptr hwnd = This. Handle;
Graphics G = graphics. fromhdc (HDC); // generated by the drawing board handle. Where: intptr HDC = E. Graphics. gethdc ();//I don't know where this method works ..
G generated using this handle method must be released later: E. Graphics. releasehdc (HDC); G. Dispose ();
Graphics G = graphics. fromimage (imagefile); // generated by the image. Where: Image imagefile = image. fromfile ("test2.jpg ");
2. Define a paint brush
Pen = new pen (color. Black, 3); // create a new paint brush
Brush = brushes. Blue; // paint brush
Pen pen2 = new pen (Brush); // generate a brush with a paint brush
Pen pen3 = new pen (brush, 4); // Add a paint brush size attribute
Pens. Black; // use a pre-defined brush with a default size of 1
3. common structure definition methods used for drawing
Font font = new font ("", 14); // The font drawstring must be defined when writing.
pointf = new pointf (); // point,
pointf [] pointsf = new pointf [] {New pointf (10, 20 ), new pointf (180,148), new pointf (260,128),
New Point (370,318), new point (200,268), new point (170,498 )}; // series Points
Rectangle rectangle = new rectangle (220,120,150,100); // rectangle
Rectanglef [] rectangles =
{
New rectanglef (0.0f, 0.0f, 100366f, 200366f ),
New rectanglef (1000000f, 2000000f, 2500000f, 500000f ),
New rectanglef (300366f, 0.0f, 50366f, 100366f)
}; // A series of rectangles
Icon = new icon ("C:/test. ICO"); // icon
Image image = image. fromfile ("C:/test.jpg", true); // Image
Graphicspath Path = new graphicspath (); // path
Path. addellipse (100,100,200,100 );
4. Basic Drawing
G. drawarc (pen, rectangle, 30,180); // arc, clockwise Angle
G. drawrectangle (pen3, rectangle); // rectangle
G. drawcurve (pen, pointsf); // curve, multi-point connection Curve
G. drawclosedcurve (pens. Red, pointsf); // close the curve and automatically connect the beginning and end
G. drawellipse (pen, rectangle); // inner tangent elliptic
G. drawicon (icon, rectangle); // icon, scaled to the specified rectangle size
G. drawiconunstretched (icon, rectangle); // the icon is aligned with the upper left corner of the rectangle.
G. drawimage (image, 100,410, 60, 30); // display the image at the specified position X, Y, and W, H (zoom)
G. drawline (pen, 10, 10, 20, 39); // draw two points, starting point X, Y, ending point X, Y
G. drawlines (pen3, pointsf); // multi-point linear connection, continuous line segments. Unlike polygon, It is not closed.
G. drawpath (pen, PATH); // path
Float startangle = 0.0f;
Float sweepangle = 145.0f;
G. drawpie (pen, rectangle, startangle, sweepangle); // two-dimensional pie chart to be split inside the specified rectangle
G. drawpolygon (pens. Pink, pointsf); // Polygon
G. drawrectangles (pens. yellowgreen, rectangles); // rectangle
G. drawstring ("test", Font, brushes. Blue, 100,200); // text
G. fillclosedcurve (brushes. Blue, pointsf, fillmode. winding, 1); // fill the curve Area
// Fill the fill series commands in the same way as above.