This article mainly introduces the method of realizing dynamic Data drawing graphic in C #, and analyzes the relative operation skill of C # to draw 2D data table based on dynamic Data in the instance form, and the friends can refer to the following
This paper describes the method of C # to implement Dynamic Data drawing graphic. Share to everyone for your reference, as follows:
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 Drawing{ Public partial class Form1:form {public Form1 () {InitializeComponent (); } private int widthadded = 0; private int heightadded = 0; private int added_value = 15; private int incremented = 3; Private double Width_max = 0.0f; Private double Height_max = 0f; private string Hstrlink; private string Vstrlink; Private Const int hor_kedu=17; Private Const int ver_kedu = 13; Private double HELPRDM = 0; private void Form1_Load (object sender, EventArgs e) {width_max=convert.todouble (panel. Clientsize.width); Height_max = convert.todouble (panel. Clientsize.height); Btnstatusinfoforb (); } private void Button1_Click (object sender, EventArgs e) {Graphics mygraphics_framwork; Pen Mypen =New Pen (Color.Blue, 0.25f); Mygraphics_framwork = panel. CreateGraphics (); for (int Increment = 0; Increment < panel. Height; Increment + = incremented) {mygraphics_framwork. DrawLine (mypen, 0, heightadded, panel. Clientsize.width, heightadded); heightadded = heightadded + added_value; } for (int Increment = 0; Increment < panel. Height; Increment + = incremented) {mygraphics_framwork. DrawLine (Mypen, widthadded, 0, widthadded, panel. Clientsize.height); widthadded = widthadded + added_value; } mygraphics_framwork. Dispose (); for (int hstart = 0; Hstart < Width_max; Hstart + = hor_kedu) {Hstrlink = Hstrlink + Hstart. ToString () + "-"; } label2. Text = Hstrlink; for (int start = (int) Height_max; start > 0; start-= ver_kedu) {Vstrlink = Vstrlink + start. ToString () + "-" + "\ n"; } label3. Text = Vstrlink + "0-"; Btnstatusinfoacti (); Button1. Enabled = False; } private void Btnstatusinfoforb () {button2. Enabled = false; Button3. Enabled = false; Button4. Enabled = false; trackbar1.enabled = false; rec_numbox.enabled = false; } private void Btnstatusinfoacti () {button2. Enabled = true; Button3. Enabled = true; Button4. Enabled = true; Trackbar1.enabled = true; Rec_numbox.enabled = true; private void Myfun () {Graphics mygraphics = panel. CreateGraphics (); Font myFont = new Font ("Times New Roman",, Fontstyle.italic); Point startPoint = new Point (0, 0); Point endPoint = new Point (30, 30); LinearGradientBrush mybrush = new LinearGradientBrush (StartPoint, EndPoint, Color.Black, Color.yellow); Mybrush.wrapmode = Wrapmode.tileflipxy; Mygraphics.drawstring ("String", MyFont, MyBrush, 0, 0); The private void button2_click (object sender, EventArgs e) {if (Parabox1.text = = null) {MessageBox. Show ("Please enter the height of the rectangle"); } else {try {Graphics mygraphics_rectangle = panel. CreateGraphics (); Pen Mypen_rec = new Pen (color.red, 3); Rectangle rect = new Rectangle (); Rect. X = 20; Rect. Y = panel. Clientsize.height-convert.toint32 (Parabox1.text); Rect. Width = 20; Rect. Height = panel. Clientsize.height; Mygraphics_rectangle = panel. CreateGraphics (); Mygraphics_rectangle.drawrectangle (Mypen_rec, rect); SolidBrush Myrectbrush = new SolidBrush (color.purple); Mygraphics_rectangle.fillrectangle (Myrectbrush, rect); Mygraphics_rectangle.dispose (); } catch (Exception excp) {MessageBox.Show (excp.message); }}}///<summary>///</summary>//<param name= "sender" ></param>// /<param name= "E" ></param> private void Button3_Click (object sender, EventArgs e) {Graphics mygrap Hics_rectangle = panel. CreAtegraphics (); if (Rec_numbox = = null) {MessageBox.Show ("Please enter the number of rectangles you want to draw"); } else {Double count = Convert.ToInt32 (Rec_numbox.text); Double tablespace = (1 * width_max)/(4 * count); Double Tablewidth = (3 * width_max)/(4 * count); Double Recoffset = tablewidth + tablespace;//pen mypen_rec = new Pen (color.red, 3); for (long rectnum = 0; Rectnum < count; rectnum++) {Random radom = new Random (); System.Threading.Thread.Sleep (20); Double Randomhegiht =radom.next (0, Convert.ToInt32 (Height_max)); Rectangle rect = new Rectangle (); Rect. X =convert.toint32 (Rectnum*recoffset); Rect. Y = Convert.ToInt32 (panel. CLIENTSIZE.HEIGHT-RANDOMHEGIHT); Rect. Width = Convert.ToInt32 (tablewidth); Rect. Height = panel. Clientsize.height; Mygraphics_rectangle = panel. CreateGraphics (); Mygraphics_rectangle.drawrectangle (Mypen_rec, rect); SolidBrush Myrectbrush = new SolidBrush (color.green); Mygraphics_rectangle.fillrectangle (Myrectbrush, rect); } mygraphics_rectangle.dispose (); } Rec_numbox.text = Added_value.tostring (); Added_value = added_value+50; } private void Button4_Click (object sender, EventArgs e) {StringFormat sf=new StringFormat (); sf. Alignment = Stringalignment.near; Graphics mygraphics = panel. CreateGraphics (); RectangleF REf = new RectangleF (12, 30, 8, 38); Font myFont = new Font ("Times New Roman", fontstyle.italic); Point startPoint = new Point (0, 0); Point endPoint = new Point (30, 30); LinearGradientBrush mybrush = new LinearGradientBrush (StartPoint, EndPoint, Color.green, Color.Blue); SolidBrush Myrectbrush = new SolidBrush (color.purple); Mybrush.wrapmode = Wrapmode.tileflipxy; Mygraphics.drawstring ("B2spirit", MyFont, MyBrush, 0, 0); Random r=new random (); int Temp=r.next (10,300); Mygraphics.drawstring (temp. ToString (), MyFont, Myrectbrush, REf, SF); } private void Trackbar1_scroll (object sender, EventArgs e) {TrackBar mytb=new TrackBar (); mytb= (TrackBar) sender; Rec_numbox.text = MyTB.Value.ToString (); } }}