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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

135

136

150

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
CSharp code
标签:
print
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!