C#2.0 print winform 打印窗体数据试试
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Drawing.Drawing2D;
7
using System.Text;
8
using System.Windows.Forms;
9
using System.Globalization;
10
11
namespace PrintTest
12
{
13
/// <summary>
14
/// 打印报告测试
15
/// 2009-02-06 涂聚文 geovindu@163.com
16
/// </summary>
17
public partial class PintUlrtDocument : Form
18
{
19
/// <summary>
20
/// 打印B超报告测试
21
/// </summary>
22
public PintUlrtDocument()
23
{
24
InitializeComponent();
25
}
26
/// <summary>
27
/// 打印
28
/// </summary>
29
/// <param name="sender"></param>
30
/// <param name="e"></param>
31
private void btnPrint_Click(object sender, EventArgs e)
32
{
33
34
}
35
/// <summary>
36
/// 打印浏览
37
/// </summary>
38
/// <param name="sender"></param>
39
/// <param name="e"></param>
40
private void btnPrintView_Click(object sender, EventArgs e)
41
{
42
if (MessageBox.Show("是否打印预览?", "打印预览", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
43
{
44
this.printPreviewDialog1.Document = this.printDocument1;
45
printPreviewDialog1.ShowDialog();
46
}
47
else
48
{
49
this.printDocument1.Print();//直接打印
50
}
51
}
52
/// <summary>
53
/// 打印设置
54
/// </summary>
55
/// <param name="sender"></param>
56
/// <param name="e"></param>
57
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
58
{
59
//字体设置
60
//this.dateTimePicker1.Format=dateTimePicker1.CustomFormat;
61
dateTimePicker1.CustomFormat = "yyyy-MM-dd";
62
//System.DateTime currentTime = new System.DateTime();
63
64
DateTime date = DateTime.Now;
65
String format = "u";
66
string year=DateTime.Now.Year.ToString();
67
string month=date.ToString(format).Substring(5,2);
68
string day = date.ToString(format).Substring(8, 2);
69
70
Font tFont = new Font("宋体", 20, FontStyle.Bold);
71
Font mFont = new Font("宋体", 15, FontStyle.Regular);
72
Font bFont = new Font("宋体", 10, FontStyle.Regular);
73
Font lFont = new Font("宋体", 10, FontStyle.Regular);
74
e.Graphics.DrawString("缔友计算机信息技术有限公司", tFont, Brushes.Black, 180, 10);
75
e.Graphics.DrawString("电脑超声诊断报告", mFont, Brushes.Black, 250, 40);
76
e.Graphics.DrawString("超声号:", bFont, Brushes.Black, 20, 70);
77
e.Graphics.DrawString(this.txtUrltID.Text.Trim(), bFont, Brushes.Black, 70, 70);
78
e.Graphics.DrawString("检查医生:", bFont, Brushes.Black, 290, 70);
79
e.Graphics.DrawString(this.combPhyName.Text.Trim(), bFont, Brushes.Black, 360, 70);
80
e.Graphics.DrawString("检查部位:", bFont, Brushes.Black, 20,90);
81
e.Graphics.DrawString(this.combCheckBody.Text.Trim(), bFont, Brushes.Black, 80, 90);
82
//划直线
83
Pen Lapiz = new Pen(Color.Black, 1);
84
int PosY = e.MarginBounds.Top;
85
int PosX = e.MarginBounds.Height;
86
e.Graphics.DrawLine(Lapiz, 20, PosY+10, 810, PosY+10);
87
88
e.Graphics.DrawString("图像特征:", bFont, Brushes.Black, 20, 120);
89
e.Graphics.DrawString(this.txtPicImpress.Text.Trim(), bFont, Brushes.Black, 40, 140);
90
e.Graphics.DrawString("身份证图像", bFont, Brushes.Black, 420, 120);
91
e.Graphics.DrawImage(this.pictureBox2.Image, 450, 140, 350, 350);
92
//
93
e.Graphics.DrawString("超声提示:", bFont, Brushes.Black, 20, 300);
94
e.Graphics.DrawString(this.combMessage.Text, bFont, Brushes.Black, 40, 320);
95
string emty = " ";
96
e.Graphics.DrawString("医师签字:", bFont, Brushes.Black, 600, 500);
97
e.Graphics.DrawString("___________________", bFont, Brushes.Black,680, 500);
98
e.Graphics.DrawString(this.combPhyName.Text+emty, lFont, Brushes.Black, 680, 500);
99
e.Graphics.DrawString("报告日期:", bFont, Brushes.Black, 600, 520);
100
e.Graphics.DrawString(year, bFont, Brushes.Black, 680, 520);
101
e.Graphics.DrawString("年", bFont, Brushes.Black, 720, 520);
102
e.Graphics.DrawString(month, bFont, Brushes.Black, 740, 520);
103
e.Graphics.DrawString("月", bFont, Brushes.Black, 760, 520);
104
e.Graphics.DrawString(day, bFont, Brushes.Black, 790, 520);
105
e.Graphics.DrawString("日", bFont, Brushes.Black, 810, 520);
106
107
108
//Graphics G;
109
//G = this.CreateGraphics();
110
//G.DrawLine(new Pen(Color.Red, 10), 50, 10, 50, 100);
111
112
//Graphics grfx = e.Graphics;
113
//grfx.DrawString(Text, Font, Brushes.Black, 0, 0);
114
//SizeF sizef = grfx.MeasureString(Text, Font);
115
//grfx.DrawLine(Pens.Black, sizef.ToPointF(), grfx.VisibleClipBounds.Size.ToPointF());
116
//grfx.DrawLine(Pens.Red, sizef.ToPointF(),grfx.VisibleClipBounds.Size.ToPointF());
117
118
画斜线
135
136
画多边形
150
页底部
168
}
169
/// <summary>
170
/// 创建图片
171
/// </summary>
172
/// <param name="e"></param>
173
public void DrawImageRectF(PaintEventArgs e)
174
{
175
176
// Create image.
177
Image newImage = Image.FromFile(Application.StartupPath + "\\Customers Pics\\CustPic.bmp");
178
179
// Create rectangle for displaying image.
180
RectangleF rect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F);
181
182
// Draw image to screen.
183
e.Graphics.DrawImage(newImage, rect);
184
}
185
/// <summary>
186
/// 加载窗体
187
/// </summary>
188
/// <param name="sender"></param>
189
/// <param name="e"></param>
190
private void PintUlrtDocument_Load(object sender, EventArgs e)
191
{
192
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
193
pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\Customers Pics\\CustPic.bmp");
194
}
195
/// <summary>
196
/// 画直线
197
/// </summary>
198
/// <param name="e"></param>
199
public void DrawLinePoint(PaintEventArgs e)
200
{
201
// Create pen.
202
Pen blackPen = new Pen(Color.Black, 3);
203
// Create points that define line.
204
Point point1 = new Point(100, 100);
205
Point point2 = new Point(500, 100);
206
// Draw line to screen.
207
e.Graphics.DrawLine(blackPen, point1, point2);
208
}
209
/// <summary>
210
/// 画直线
211
/// </summary>
212
/// <param name="e"></param>
213
protected override void OnPaint(PaintEventArgs e)
214
{
215
Pen myPen = new Pen(Color.Red);
216
Graphics g = e.Graphics;
217
myPen.Width = 5;
218
g.DrawLine(myPen, 1, 1, 100, 100);
219
220
}
221
222
身份证
309
/// <summary>
310
///
311
/// </summary>
312
/// <param name="args"></param>
313
//public static void date(string[] args)
314
//{
315
// DateTime dt = DateTime.Now;
316
// String[] format = {
317
// "d ", "D ",
318
// "f ", "F ",
319
// "g ", "G ",
320
// "m ",
321
// "r ",
322
// "s ",
323
// "t ", "T ",
324
// "u ", "U ",
325
// "y ",
326
// "dddd, MMMM dd yyyy ",
327
// //"ddd, MMM d \ " '\ "yy ",
328
// "dddd, MMMM dd ",
329
// "M/yy ",
330
// "dd-MM-yy ",
331
// };
332
// String date;
333
// for (int i = 0; i < format.Length; i++) {
334
// date = dt.ToString(format[i], DateTimeFormatInfo.InvariantInfo);
335
// Console.WriteLine(String.Concat(format[i], " : " , date));
336
// }
337
//}
338
339
}
340
}
using System;2
using System.Collections.Generic;3
using System.ComponentModel;4
using System.Data;5
using System.Drawing;6
using System.Drawing.Drawing2D;7
using System.Text;8
using System.Windows.Forms;9
using System.Globalization; 10

11
namespace PrintTest12
{13
/// <summary>14
/// 打印报告测试 15
/// 2009-02-06 涂聚文 geovindu@163.com16
/// </summary>17
public partial class PintUlrtDocument : Form18
{19
/// <summary>20
/// 打印B超报告测试21
/// </summary>22
public PintUlrtDocument()23
{24
InitializeComponent();25
}26
/// <summary>27
/// 打印28
/// </summary>29
/// <param name="sender"></param>30
/// <param name="e"></param>31
private void btnPrint_Click(object sender, EventArgs e)32
{33

34
}35
/// <summary>36
/// 打印浏览37
/// </summary>38
/// <param name="sender"></param>39
/// <param name="e"></param>40
private void btnPrintView_Click(object sender, EventArgs e)41
{42
if (MessageBox.Show("是否打印预览?", "打印预览", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)43
{44
this.printPreviewDialog1.Document = this.printDocument1;45
printPreviewDialog1.ShowDialog();46
}47
else48
{49
this.printDocument1.Print();//直接打印50
}51
}52
/// <summary>53
/// 打印设置54
/// </summary>55
/// <param name="sender"></param>56
/// <param name="e"></param>57
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)58
{59
//字体设置60
//this.dateTimePicker1.Format=dateTimePicker1.CustomFormat;61
dateTimePicker1.CustomFormat = "yyyy-MM-dd";62
//System.DateTime currentTime = new System.DateTime(); 63

64
DateTime date = DateTime.Now;65
String format = "u";66
string year=DateTime.Now.Year.ToString();67
string month=date.ToString(format).Substring(5,2);68
string day = date.ToString(format).Substring(8, 2);69

70
Font tFont = new Font("宋体", 20, FontStyle.Bold);71
Font mFont = new Font("宋体", 15, FontStyle.Regular);72
Font bFont = new Font("宋体", 10, FontStyle.Regular);73
Font lFont = new Font("宋体", 10, FontStyle.Regular);74
e.Graphics.DrawString("缔友计算机信息技术有限公司", tFont, Brushes.Black, 180, 10);75
e.Graphics.DrawString("电脑超声诊断报告", mFont, Brushes.Black, 250, 40);76
e.Graphics.DrawString("超声号:", bFont, Brushes.Black, 20, 70);77
e.Graphics.DrawString(this.txtUrltID.Text.Trim(), bFont, Brushes.Black, 70, 70);78
e.Graphics.DrawString("检查医生:", bFont, Brushes.Black, 290, 70);79
e.Graphics.DrawString(this.combPhyName.Text.Trim(), bFont, Brushes.Black, 360, 70);80
e.Graphics.DrawString("检查部位:", bFont, Brushes.Black, 20,90);81
e.Graphics.DrawString(this.combCheckBody.Text.Trim(), bFont, Brushes.Black, 80, 90);82
//划直线83
Pen Lapiz = new Pen(Color.Black, 1);84
int PosY = e.MarginBounds.Top;85
int PosX = e.MarginBounds.Height;86
e.Graphics.DrawLine(Lapiz, 20, PosY+10, 810, PosY+10);87
88
e.Graphics.DrawString("图像特征:", bFont, Brushes.Black, 20, 120);89
e.Graphics.DrawString(this.txtPicImpress.Text.Trim(), bFont, Brushes.Black, 40, 140);90
e.Graphics.DrawString("身份证图像", bFont, Brushes.Black, 420, 120);91
e.Graphics.DrawImage(this.pictureBox2.Image, 450, 140, 350, 350);92
//93
e.Graphics.DrawString("超声提示:", bFont, Brushes.Black, 20, 300);94
e.Graphics.DrawString(this.combMessage.Text, bFont, Brushes.Black, 40, 320);95
string emty = " ";96
e.Graphics.DrawString("医师签字:", bFont, Brushes.Black, 600, 500);97
e.Graphics.DrawString("___________________", bFont, Brushes.Black,680, 500);98
e.Graphics.DrawString(this.combPhyName.Text+emty, lFont, Brushes.Black, 680, 500);99
e.Graphics.DrawString("报告日期:", bFont, Brushes.Black, 600, 520);100
e.Graphics.DrawString(year, bFont, Brushes.Black, 680, 520);101
e.Graphics.DrawString("年", bFont, Brushes.Black, 720, 520);102
e.Graphics.DrawString(month, bFont, Brushes.Black, 740, 520);103
e.Graphics.DrawString("月", bFont, Brushes.Black, 760, 520);104
e.Graphics.DrawString(day, bFont, Brushes.Black, 790, 520);105
e.Graphics.DrawString("日", bFont, Brushes.Black, 810, 520);106
107
108
//Graphics G;109
//G = this.CreateGraphics();110
//G.DrawLine(new Pen(Color.Red, 10), 50, 10, 50, 100);111

112
//Graphics grfx = e.Graphics;113
//grfx.DrawString(Text, Font, Brushes.Black, 0, 0);114
//SizeF sizef = grfx.MeasureString(Text, Font);115
//grfx.DrawLine(Pens.Black, sizef.ToPointF(), grfx.VisibleClipBounds.Size.ToPointF());116
//grfx.DrawLine(Pens.Red, sizef.ToPointF(),grfx.VisibleClipBounds.Size.ToPointF());117

118
画斜线135

136
画多边形 150
页底部 168
}169
/// <summary>170
/// 创建图片171
/// </summary>172
/// <param name="e"></param>173
public void DrawImageRectF(PaintEventArgs e)174
{175

176
// Create image.177
Image newImage = Image.FromFile(Application.StartupPath + "\\Customers Pics\\CustPic.bmp");178

179
// Create rectangle for displaying image.180
RectangleF rect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F);181

182
// Draw image to screen.183
e.Graphics.DrawImage(newImage, rect);184
}185
/// <summary>186
/// 加载窗体187
/// </summary>188
/// <param name="sender"></param>189
/// <param name="e"></param>190
private void PintUlrtDocument_Load(object sender, EventArgs e)191
{192
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;193
pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\Customers Pics\\CustPic.bmp");194
}195
/// <summary>196
/// 画直线197
/// </summary>198
/// <param name="e"></param>199
public void DrawLinePoint(PaintEventArgs e)200
{201
// Create pen. 202
Pen blackPen = new Pen(Color.Black, 3);203
// Create points that define line. 204
Point point1 = new Point(100, 100);205
Point point2 = new Point(500, 100);206
// Draw line to screen. 207
e.Graphics.DrawLine(blackPen, point1, point2);208
} 209
/// <summary>210
/// 画直线211
/// </summary>212
/// <param name="e"></param>213
protected override void OnPaint(PaintEventArgs e)214
{215
Pen myPen = new Pen(Color.Red); 216
Graphics g = e.Graphics;217
myPen.Width = 5;218
g.DrawLine(myPen, 1, 1, 100, 100);219

220
}221

222
身份证 309
/// <summary>310
/// 311
/// </summary>312
/// <param name="args"></param>313
//public static void date(string[] args) 314
//{315
// DateTime dt = DateTime.Now;316
// String[] format = {317
// "d ", "D ",318
// "f ", "F ",319
// "g ", "G ",320
// "m ",321
// "r ",322
// "s ",323
// "t ", "T ",324
// "u ", "U ",325
// "y ",326
// "dddd, MMMM dd yyyy ",327
// //"ddd, MMM d \ " '\ "yy ",328
// "dddd, MMMM dd ",329
// "M/yy ",330
// "dd-MM-yy ",331
// };332
// String date;333
// for (int i = 0; i < format.Length; i++) {334
// date = dt.ToString(format[i], DateTimeFormatInfo.InvariantInfo);335
// Console.WriteLine(String.Concat(format[i], " : " , date));336
// } 337
//}338

339
}340
}
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)


浙公网安备 33010602011771号