C#2.0 数字“0”是有一道斜线,打印虚线,Pos打印
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.Data.SqlClient;
10
using System.Drawing.Printing;
11
12
namespace printpos
13
{
14
/// <summary>
15
/// 打印POS样式
16
/// 涂聚文 geovindu@163.com
17
/// </summary>
18
public partial class FrmPrintPos : Form
19
{
20
public FrmPrintPos()
21
{
22
InitializeComponent();
23
}
24
/// <summary>
25
/// 打印
26
/// </summary>
27
/// <param name="sender"></param>
28
/// <param name="e"></param>
29
private void btnPrint_Click(object sender, EventArgs e)
30
{
31
if (MessageBox.Show("是否打印预览?", "打印预览", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
32
{
33
PrintDialog MyPrintDialog = new PrintDialog();
34
MyPrintDocument.PrinterSettings = MyPrintDialog.PrinterSettings;
35
MyPrintDocument.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings;
36
MyPrintDocument.DefaultPageSettings.Margins = new Margins(40, 40, 40, 40);
37
PrintPreviewDialog MyPrintPreviewDialog = new PrintPreviewDialog();
38
MyPrintPreviewDialog.Document = MyPrintDocument;
39
MyPrintPreviewDialog.ShowDialog();
40
41
42
}
43
else
44
{
45
this.MyPrintDocument.Print();//直接打印
46
}
47
}
48
/// <summary>
49
/// 打印内容设置
50
/// 涂聚文 geovindu@163.com
51
/// 缔友计算机信息技术有限公司 www.dupcit.com
52
/// </summary>
53
/// <param name="sender"></param>
54
/// <param name="e"></param>
55
private void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
56
{
57
//文字右对齐
58
StringFormat sf = new StringFormat(StringFormatFlags.DirectionRightToLeft);
59
//划虚线
60
Pen ftqGoal = new Pen(Color.Black, 1);
61
ftqGoal.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
62
//StringAlignment.Center;或者:StringAlignment.Far;或者:StringAlignment.Near;
63
Brush brush = new SolidBrush(Color.Black);//画刷
64
Brush brred = new SolidBrush(Color.Red);//
65
Font titleFont = new Font("黑体", 24, FontStyle.Bold);//标题字体
66
Font font = new Font("Consolas", 8, FontStyle.Regular);//数字0字有斜线的字体:WST_Ital, 01 DigitGraphics , 00 Starmap Truetype,Consolas,
67
//Font font = new Font("WST_Engl", 8);//正文字体
68
Font headerFont = new Font("黑体", 12, FontStyle.Bold);//列名标题
69
Font footerFont = new Font("Arial", 8);//页脚显示页数的字体
70
Font upLineFont = new Font("Arial", 9, FontStyle.Bold);//当header分两行显示的时候,上行显示的字体。
71
Font underLineFont = new Font("Arial", 8);//当header分两行显示的时候,下行显示的字
72
//
73
e.Graphics.DrawLine(ftqGoal, 1, 5, 250, 5);
74
//
75
e.Graphics.DrawString("欢迎光临缔友书城南山城", font, brush, 45, 55);
76
//
77
e.Graphics.DrawString("若有质量问题三日内凭票退换", font, brush, 40, 70);
78
//
79
e.Graphics.DrawString("95925", font, brush, 1, 85);
80
e.Graphics.DrawString("#20000000372", font, brush, 250, 85, sf);
81
//名称,单价,数量,金额
82
e.Graphics.DrawString("名称", font, brush, 1, 100);
83
e.Graphics.DrawString("单价", font, brush, 60, 100);
84
e.Graphics.DrawString("数量", font, brush, 120, 100);
85
e.Graphics.DrawString("金额", font, brush, 220, 100);
86
//1
87
e.Graphics.DrawString("装订夹", font, brush, 1, 115);
88
e.Graphics.DrawString("19.00", font, brush, 60, 115);
89
e.Graphics.DrawString("200", font, brush, 120, 115);
90
e.Graphics.DrawString("3800", font, brush, 250, 115, sf);
91
//2
92
e.Graphics.DrawString("不锈钢夹", font, brush, 1, 130);
93
e.Graphics.DrawString("98.00", font, brush, 60, 130);
94
e.Graphics.DrawString("90", font, brush, 120, 130);
95
e.Graphics.DrawString("8820.00", font, brush, 250, 130, sf);
96
//3
97
e.Graphics.DrawString("固体胶", font, brush, 1, 145);
98
e.Graphics.DrawString("18.50", font, brush, 60, 145);
99
e.Graphics.DrawString("60", font, brush, 120, 145);
100
e.Graphics.DrawString("1110.00", font, brush, 250, 145, sf);
101
//4
102
e.Graphics.DrawString("档案盒", font, brush, 1, 160);
103
e.Graphics.DrawString("4.80", font, brush, 60, 160);
104
e.Graphics.DrawString("265", font, brush, 120, 160);
105
e.Graphics.DrawString("1272", font, brush, 250, 160, sf);
106
//划虚线
107
//Pen ftqGoal = new Pen(Color.Black, 1);
108
//ftqGoal.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
109
e.Graphics.DrawLine(ftqGoal, 1, 182, 250, 182);
110
//小计
111
e.Graphics.DrawString("(小计)", font, brush, 1, 190);
112
e.Graphics.DrawString("4项", font, brush, 60, 190);
113
e.Graphics.DrawString("615件", font, brush, 120, 190);
114
e.Graphics.DrawString("15000.00", font, brush, 250, 190, sf);
115
//实收
116
e.Graphics.DrawString("实收", font, brush, 1, 205);
117
e.Graphics.DrawString("15000.00", font, brush, 250, 205, sf);
118
//找回
119
e.Graphics.DrawString("找回", font, brush, 1, 220);
120
e.Graphics.DrawString("0.00", font, brush, 250, 220, sf);
121
//划虚线
122
// Pen ftqGoal = new Pen(Color.Black, 1);
123
//ftqGoal.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
124
e.Graphics.DrawLine(ftqGoal, 1, 242, 250, 242);
125
//
126
e.Graphics.DrawString("2503", font, brush, 1, 250);
127
e.Graphics.DrawString("2008年11月19日 10:48", font, brush, 250, 250, sf);
128
//
129
e.Graphics.DrawString("一次消费满50元,免费停车2小时(当日有效)", font, brush, 1, 265);
130
//
131
e.Graphics.DrawString("免费停车票到一楼总服务台领取", font, brush, 25, 280);
132
//
133
e.Graphics.DrawString("WWW.DUPCIT.COM 客户服务热线:86369385", font, brush, 1, 295);
134
135
}
136
}
137
}

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

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个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帮你做增删改查!!