首页 > 应用开发 > IT综合 > 浅析C#中图形编程之一(转)
| using System; using System.Windows.Forms; using System.Drawing; public class Hello:Form { public Hello() { this.Paint += new PaintEventHandler(f1_paint); } private void f1_paint(object sender,PaintEventArgs e) { Graphics g = e.Graphics; g.DrawString("你好,C#!",new Font("Verdana",20), new SolidBrush(Color.Tomato),40,40); g.DrawRectangle(new Pen(Color.Pink,3),20,20,150,100); } public static void Main() { Application.Run(new Hello()); } } |
| Graphics g = e.Graphics; g.PageUnit = GraphicsUnit.Inch |
| ColorDialog cd = new ColorDialog(); |
| using System; using System.Drawing; using System.Windows.Forms; public class Clr:Form{ Button b1 = new Button(); TextBox tb = new TextBox(); ColorDialog clg = new ColorDialog(); public Clr(){ b1.Click += new EventHandler(b1_click); b1.Text = "选择颜色"; tb.Location = new Point(50,50); this.Controls.Add(b1); this.Controls.Add(tb); } public void b1_click(object sender, EventArgs e){ clg.ShowDialog(); tb.BackColor = clg.Color; } public static void Main() { Application.Run(new Clr()); } } |
| using System; using System.Drawing; using System.Windows.Forms; public class Fonts:Form { Button b1 = new Button(); TextBox tb = new TextBox(); FontDialog flg = new FontDialog(); public Fonts() { b1.Click += new EventHandler(b1_click); b1.Text = "选择字体"; tb.Location = new Point(50,50); this.Controls.Add(b1); this.Controls.Add(tb); } public void b1_click(object sender, EventArgs e) { clg.ShowDialog(); tb.FontName = flg.Font; } public static void Main() { Application.Run(new Fonts()); } } |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/79548/viewspace-925518/ ,如需转载,请注明出处,否则将追究法律责任。