c#-drawing a drawing

Source: Internet
Author: User

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {public partial class Firstform:fo        RM {public Firstform () {InitializeComponent ();            } private void Button1_Click (object sender, EventArgs e) {Form1 f1 = new Form1 (); F1.        Show ();            } private void Button2_Click (object sender, EventArgs e) {instance 7_8 draw rectangle Form8=new instance 7_8 draw Rectangle (); FORM8.        Show ();             } private void Button3_Click (object sender, EventArgs e) {instance 7_9 draw smooth curve form9 = new instance 7_9 draw smooth curve (); Form9.        Show (); } private void Button4_Click (object sender, EventArgs e) {instance 7_10 draw Bézier curve FORM10 = new instance 7_10 draw Bezier            Curve (); FORM10.        Show ();     private void Button5_click (object sender, EventArgs e) {       Instance 7_11 Draw Polygon Form11 = new instance 7_11 draw Polygon (); Form11.        Show ();            } private void Button6_click (object sender, EventArgs e) {instance 7_12 draw ellipse form12 = new instance 7_12 draw ellipse (); Form12.        Show ();            } private void Button7_click (object sender, EventArgs e) {instance 7_13 draw text Form13 = new instance 7_13 draw text (); Form13.        Show ();            } private void Button8_click (object sender, EventArgs e) {instance 7_14 display image form14 = new instance 7_14 display image (); Form14.        Show ();            } private void Button9_click (object sender, EventArgs e) {instance 7_15 refresh image form15 = new instance 7_15 refresh image (); Form15.        Show ();            } private void Button10_click (object sender, EventArgs e) {Draw Column chart formzx = new Draw Column chart ();        Formzx.show ();            } private void Button11_click (object sender, EventArgs e) {Verification Code YZM = new Verification Code (); Yzm.        Show (); } Private VOID Firstform_load (object sender, EventArgs e) {}}} 

/* * Draw straight lines using DrawLine and DrawLines. */using system;using system.collections.generic;using system.componentmodel;using System.Data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {public    partial class Form1: Form    {public        Form1 ()        {            InitializeComponent ();        }        private void Form1_paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;            Pen p = new Pen (color.black, 2.5f);            G.drawline (P, new Point (Ten), New Point (+));            Point[] points = {new Point (50,20), new Point (250,20), new Point (                                250,70), New Point (50,20)};            G.drawlines (p, points  );            G.dispose ();        }        private void Form1_Load (object sender, EventArgs e)        {        }}}    
Operation Result:

/* * Use DrawRectangle, FillRectangle method to draw, fill rectangle outline. */using system;using system.collections.generic;using system.componentmodel;using System.Data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace instance 7_8 Draw Rectangle {Public partial class instance 7_8 draw rectangle: Fo        RM {Public instance 7_8 draw rectangle () {InitializeComponent ();            The private void instance 7_8 draws the rectangle _paint (object sender, PaintEventArgs e) {Graphics g = e.graphics;            Pen p = new Pen (color.black, 2.0f);            Rectangle Rct1 = new Rectangle (new Point (Ten), New Size (80, 40));         G.drawrectangle (P, Rct1);            Draw the rectangle outline//Fill rectangle area Rectangle rct2 = new Rectangle (new Point (+), new Size (200, 50));            SolidBrush brush = new SolidBrush (Color.Blue);            G.fillrectangle (brush, RCT2);        G.dispose (); The private void instance 7_8 draws the rectangle _load (object sender, EventArgs e) {this. Text = "Instance 7-8Draw Rectangle "; }    }}
Operation Result:

/* * Use the DrawCurve method to draw a smooth curve. */using system;using system.collections.generic;using system.componentmodel;using System.Data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {Public    partial class instance 7_ 9 Draw Smooth curve: Form    {public        instance 7_9 draw Smooth curve ()        {            InitializeComponent ();        }        private void instance 7_9 draw Smooth curve _paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;            Draw a smooth curve            pen p = new Pen (color.black, 2.0f);            Point[] points = {new Point (50,100), new Point (+), new point (+, +), new Point (                             300, 75) };            G.drawcurve (p, points, 0.8f);            G.dispose ();        }        private void instance 7_9 draw Smooth curve _load (object sender, EventArgs e)        {        }}}    
Operation result;

Draw Bézier curves using system;using system.collections.generic;using system.componentmodel;using system.data;using System.drawing;using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {public    The partial class instance 7_10 draws a Bezier curve: the Form    {public        instance 7_10 draws the Bezier curve ()        {            InitializeComponent ();        }        private void Instance 7_10 draws Bezier _paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;            Draw Bezier curve            pen p = new Pen (color.black, 2.0f);            Point P1 = new Point (.);            Point P2 = new Point (+);            Point p3 = new Point (n, a);            Point P4 = new Point (in.);            G.drawbezier (P, p1, p2, p3, p4);            G.dispose ();        }        private void instance 7_10 drawing Bézier curve _load (object sender, EventArgs e)        {        }}}    
Operation Result:

Draw, fill polygon using system;using system.collections.generic;using system.componentmodel;using system.data;using System.drawing;using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {public partial        class instance 7_11 Draw polygon: Form {Public instance 7_11 draw polygon () {InitializeComponent ();            The private void instance 7_11 draws the polygon _paint (object sender, PaintEventArgs e) {Graphics g = e.graphics;            Draw Polygon Outline Pen p = new Pen (color.black, 2.0f);                         G.drawpolygon (p, new point[]{new Point (20,20), new Point (120,20),            New Point (70,70), new Point (20,20)});            Fill polygon Area SolidBrush brush = new SolidBrush (Color.Blue); Point[] points = {new Point (150,70), new Point (250,70), new Point (200,20), new Point (150,70)            };            G.fillpolygon (brush, points); G.        Dispose (); } private void instance 7_11 draw polygon _load (object sender, EventArgs e) {}}}
Operation Result:

Draw ellipse using system;using system.collections.generic;using system.componentmodel;using system.data;using System.drawing;using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {public    The partial class instance 7_12 draws an ellipse: the Form    {public        instance 7_12 draws the ellipse ()        {            InitializeComponent ();        }        private void Instance 7_12 draws an ellipse _paint (object sender, PaintEventArgs e)        {            Graphics g = e.graphics;            Pen p = new Pen (color.black, 2.0f);            G.drawellipse (P, new Rectangle (+, +,));     Draw Ellipse            SolidBrush brush = new SolidBrush (color.blue);            G.fillellipse (Brush, new Rectangle (+/-);  Fill ellipse            g.dispose ();        }        private void Instance 7_12 draw ellipse _load (object sender, EventArgs e)        {        }}}    
Operation Result:

Draws the text that is filled by the picture. Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing;    Using system.linq;using system.text;using system.windows.forms;using System.Drawing.Drawing2D; namespace instance 7_7 drawing graphics {        Public partial class instance 7_13 drawing text: Form {Public instance 7_13 draw text () {InitializeComponent ();            } private void instance 7_13 draw literal _paint (object sender, PaintEventArgs e) {Graphics g = e.graphics;            Image image = Image.FromFile (Application.startuppath + @ "\p01.jpg");            TextureBrush brush = new TextureBrush (image);            Create fonts Font font = new Font ("Blackbody", Fontstyle.underline ^ fontstyle.bold);            g.DrawString ("Yantai University", Font, brush, new Point (10, 10));        G.dispose (); } private void instance 7_13 draw text _load (object sender, EventArgs e) {}}}
Operation Result:

/* * Display images and save images. */using system;using system.collections.generic;using system.componentmodel;using System.Data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {Public partial class instance 7_14 display Image: F        ORM {Public instance 7_14 display image () {InitializeComponent ();        } Graphics G;        Bitmap Bitmap;            private void Button1_Click (object sender, EventArgs e) {g = Picturebox1.creategraphics ();            Bitmap = new Bitmap (Application.startuppath + @ "\p01.jpg");     G.drawimage (bitmap, 0, 0); Draws the bitmap from the upper-left corner of the PictureBox1 control.            Dispose ();        G.dispose (); private void Button2_Click (object sender, EventArgs e) {bitmap = new Bitmap (application.start            Uppath + @ "\p01.jpg");    Bitmap image = New Bitmap (picturebox1.width, picturebox1.height);            Save the image with the height and width of the picture frame G = graphics.fromimage (image); G.draWimage (bitmap, 0,0); Image.            Save (@ "D:\p01.gif", System.Drawing.Imaging.ImageFormat.Gif); Bitmap.            Dispose (); Image.            Dispose ();        G.dispose (); } private void instance 7_14 display image _load (object sender, EventArgs e) {}}}
Operation Result:

Refreshes the image. Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace instance 7_7 drawing graphics {Public partial class instance 7_15 Refresh Image: F        ORM {Public instance 7_15 refresh image () {InitializeComponent ();        } Bitmap Bitmap;        Graphics G; private void Button1_Click (object sender, EventArgs e) {bitmap = new Bitmap (picturebox1.width, Pictureb Ox1.            Height);            Picturebox1.backgroundimage = bitmap;            g = Graphics.fromimage (bitmap);            G.clear (Picturebox1.backcolor);            Pen pen=new Pen (color.red, 3.0f);            Point P1 = new Point (10, 10);            Point P2 = new Point (150, 100);            G.drawline (pen, p1, p2);        G.dispose ();  } private void Button2_Click (object sender, EventArgs e) {bitmap = new Bitmap (Picturebox1.width,          Picturebox1.height);  Picturebox1.backgroundimage = bitmap;            g = Graphics.fromimage (bitmap);                       G.clear (Picturebox1.backcolor);            Pen pen = new Pen (color.red, 3.0f);            Rectangle rec = new Rectangle (0, 0, 100, 100);            G.drawellipse (pen, rec);        G.dispose (); } private void instance 7_15 Refresh image _load (object sender, EventArgs e) {}}}
Operation Result:



c#-drawing a drawing

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.