C# 2.0 Graphics 画雪人
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Drawing.Printing;
9
10namespace PrintTest
11{
12 /// <summary>
13 /// 打印雪人图像窗体
14 /// 2009-02-16 涂聚文
15 /// </summary>
16 public partial class printDram : Form
17 {
18 /// <summary>
19 /// 打印雪人图像窗体
20 /// </summary>
21 public printDram()
22 {
23 InitializeComponent();
24 }
25 /// <summary>
26 /// 窗体加载
27 /// </summary>
28 /// <param name="sender"></param>
29 /// <param name="e"></param>
30 private void printDram_Load(object sender, EventArgs e)
31 {
32
33 }
34 /// <summary>
35 /// 打印文档
36 /// </summary>
37 /// <param name="sender"></param>
38 /// <param name="e"></param>
39 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
40 {
41 const int MID = 150;
42 const int Top = 50;
43 this.BackColor = Color.Cyan;
44 this.Width = 310;
45 this.Height = 260;
46 this.Text = "simple graphics snowman";
47
48 Pen blue = new Pen(Color.Blue);
49 Pen yellow = new Pen(Color.Yellow);
50 Pen white = new Pen(Color.White);
51 Pen red = new Pen(Color.Red);
52 Pen black = new Pen(Color.Black);
53 Brush brWhite = white.Brush;
54 Brush brBlack = black.Brush;
55 Brush brRed = red.Brush;
56 Graphics g = e.Graphics;
57
58 g.DrawRectangle(blue, 0, 175, 300, 50); //sky
59 g.DrawEllipse(yellow, -40, -40, 80, 80); //sun
60 g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head
61 g.FillEllipse(brRed, MID - 35, Top + 35, 70, 50); //top
62 g.FillEllipse(brRed, MID - 50, Top + 80, 100, 60); //bot
63 g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye
64 g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye
65 g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:
66 //arms
67 g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);
68 g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);
69
70 g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top
71 g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);
72
73 }
74 /// <summary>
75 /// 打印
76 /// </summary>
77 /// <param name="sender"></param>
78 /// <param name="e"></param>
79 private void btnprint_Click(object sender, EventArgs e)
80 {
81 if (MessageBox.Show("是否打印预览?", "打印预览", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
82 {
83 this.printPreviewDialog1.Document = this.printDocument1;
84 printPreviewDialog1.ShowDialog();
85 }
86 else
87 {
88 this.printDocument1.Print();//直接打印
89 }
90 }
91 /// <summary>
92 /// 窗体外观
93 /// </summary>
94 /// <param name="sender"></param>
95 /// <param name="e"></param>
96 private void printDram_Paint(object sender, PaintEventArgs e)
97 {
98 const int MID = 150;
99 const int Top = 50;
100 this.BackColor = Color.Cyan;
101 this.Width = 310;
102 this.Height = 260;
103 this.Text = "simple graphics snowman";
104
105 Pen blue = new Pen(Color.Blue);
106 Pen yellow = new Pen(Color.Yellow);
107 Pen white = new Pen(Color.White);
108 Pen red = new Pen(Color.Red);
109 Pen black = new Pen(Color.Black);
110 Brush brWhite = white.Brush;
111 Brush brBlack = black.Brush;
112 Brush brRed = red.Brush;
113 Graphics g = e.Graphics;
114
115 g.DrawRectangle(blue, 0, 175, 300, 50); //sky
116 g.DrawEllipse(yellow, -40, -40, 80, 80); //sun
117 g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head
118 g.FillEllipse(brWhite, MID - 35, Top + 35, 70, 50); //top
119 g.FillEllipse(brWhite, MID - 50, Top + 80, 100, 60); //bot
120 g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye
121 g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye
122 g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:
123 //arms
124 g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);
125 g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);
126
127 g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top
128 g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);
129 }
130 }
131}
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Drawing.Printing;
9
10namespace PrintTest
11{
12 /// <summary>
13 /// 打印雪人图像窗体
14 /// 2009-02-16 涂聚文
15 /// </summary>
16 public partial class printDram : Form
17 {
18 /// <summary>
19 /// 打印雪人图像窗体
20 /// </summary>
21 public printDram()
22 {
23 InitializeComponent();
24 }
25 /// <summary>
26 /// 窗体加载
27 /// </summary>
28 /// <param name="sender"></param>
29 /// <param name="e"></param>
30 private void printDram_Load(object sender, EventArgs e)
31 {
32
33 }
34 /// <summary>
35 /// 打印文档
36 /// </summary>
37 /// <param name="sender"></param>
38 /// <param name="e"></param>
39 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
40 {
41 const int MID = 150;
42 const int Top = 50;
43 this.BackColor = Color.Cyan;
44 this.Width = 310;
45 this.Height = 260;
46 this.Text = "simple graphics snowman";
47
48 Pen blue = new Pen(Color.Blue);
49 Pen yellow = new Pen(Color.Yellow);
50 Pen white = new Pen(Color.White);
51 Pen red = new Pen(Color.Red);
52 Pen black = new Pen(Color.Black);
53 Brush brWhite = white.Brush;
54 Brush brBlack = black.Brush;
55 Brush brRed = red.Brush;
56 Graphics g = e.Graphics;
57
58 g.DrawRectangle(blue, 0, 175, 300, 50); //sky
59 g.DrawEllipse(yellow, -40, -40, 80, 80); //sun
60 g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head
61 g.FillEllipse(brRed, MID - 35, Top + 35, 70, 50); //top
62 g.FillEllipse(brRed, MID - 50, Top + 80, 100, 60); //bot
63 g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye
64 g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye
65 g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:
66 //arms
67 g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);
68 g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);
69
70 g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top
71 g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);
72
73 }
74 /// <summary>
75 /// 打印
76 /// </summary>
77 /// <param name="sender"></param>
78 /// <param name="e"></param>
79 private void btnprint_Click(object sender, EventArgs e)
80 {
81 if (MessageBox.Show("是否打印预览?", "打印预览", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
82 {
83 this.printPreviewDialog1.Document = this.printDocument1;
84 printPreviewDialog1.ShowDialog();
85 }
86 else
87 {
88 this.printDocument1.Print();//直接打印
89 }
90 }
91 /// <summary>
92 /// 窗体外观
93 /// </summary>
94 /// <param name="sender"></param>
95 /// <param name="e"></param>
96 private void printDram_Paint(object sender, PaintEventArgs e)
97 {
98 const int MID = 150;
99 const int Top = 50;
100 this.BackColor = Color.Cyan;
101 this.Width = 310;
102 this.Height = 260;
103 this.Text = "simple graphics snowman";
104
105 Pen blue = new Pen(Color.Blue);
106 Pen yellow = new Pen(Color.Yellow);
107 Pen white = new Pen(Color.White);
108 Pen red = new Pen(Color.Red);
109 Pen black = new Pen(Color.Black);
110 Brush brWhite = white.Brush;
111 Brush brBlack = black.Brush;
112 Brush brRed = red.Brush;
113 Graphics g = e.Graphics;
114
115 g.DrawRectangle(blue, 0, 175, 300, 50); //sky
116 g.DrawEllipse(yellow, -40, -40, 80, 80); //sun
117 g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head
118 g.FillEllipse(brWhite, MID - 35, Top + 35, 70, 50); //top
119 g.FillEllipse(brWhite, MID - 50, Top + 80, 100, 60); //bot
120 g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye
121 g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye
122 g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:
123 //arms
124 g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);
125 g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);
126
127 g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top
128 g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);
129 }
130 }
131}
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)