C # Graphic draw circles, triangles, ellipses, pictures

Source: Internet
Author: User

Original: C # Graphic drawing circles, triangles, ellipses, pictures

You can draw graphics, line segments, circles, text, graphics, and so on in form and panel.
The drawing code must be placed inside the OnPaint () function, because the function is called when the form refreshes, and the drawing is refreshed again.
The sample code draws a graphic on the panel to simply describe the plotting line and the drawing principle.

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Reflection;namespacetestgraphic{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidPanel1_paint (Objectsender, PaintEventArgs e) {Graphics GC=E.graphics; ///set the color of a drawingBrush Greenbrush =NewSolidBrush (Color.green); intRadius = -; //Draws a circle, (0, 0) is the coordinate of the upper-left corner, radius is the diameterGc. FillEllipse (Greenbrush,0,0, radius, radius); Brush Yellowbush=NewSolidBrush (Color.yellow); //The ellipse is drawn, in fact, a special kind of ellipse, that is, two fixed-point coincident, (50, 60) is the coordinates of the upper left corner,//width of 70-bit ellipse, height of 100-bit ellipseGc. FillEllipse (Yellowbush, -, -, -, -); //draws a triangle, specifying red and line width 5. Three vertices are (150,160) (200, 210) (280, 180), and three lines are drawn. Pen pen =NewPen (Color.Red,5); Gc. DrawLine (pen, Max, the, $, About); Gc. DrawLine (pen, $, About,280, the); Gc. DrawLine (pen, Max, the,280, the); ///Draws a rectangle, (50,300) the upper-left coordinate, 110-bit width, and 80 height. Gc. DrawRectangle (pen, -, -, the, the); Brush Bluebrush=NewSolidBrush (Color.Blue); ///Draw TextGc. DrawString ("graphic Examples of drawing graphs",NewFont ("Song Body", -, Fontstyle.italic), Bluebrush,NewPointF ( -, -)); ///Draw picture TestGraphic.Properties.Resources.niang as the name of the picture in the resource, you can set the picture to the panel's background map first ,///get the name of the picture, and then empty the panel's background image. (400,20) is the upper-left coordinate of the picture, and 300,300 is the width and height at which the picture will be displayed.///is not the width and height of the picture itself. Image image =Global:: TestGraphic.Properties.Resources.niang; Gc. DrawImage (Image,NewRectangle ( -, -, -, -)); }    }}

C # Graphic draw circles, triangles, ellipses, pictures

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.