C#2.0 数字“0”是有一道斜线,打印虚线,Pos打印
2009-06-13 15:54
253 查看
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
}
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
}
相关文章推荐
- C# 打印小票 POS
- C# 调用系统API函数直接连接pos打印机 打印
- 一道无聊的数学题 abcd*x = fghi (分别为9个不重复的1-9的数字) 用C#实现
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- c# 怎么将传进来的一串数字,在键盘在记事本上打印
- C# 打印小票 POS
- 一道生成不重复随机数字的C#笔试编程题
- C#使用ESC指令控制POS打印机打印小票
- C# 打印小票 POS
- 【转】C#使用ESC指令控制POS打印机打印小票
- 黑马程序员之C#编程基础学习笔记:不断要求用户输入一个数字,然后打印这个数字的二倍,当用户输入q的时候程序退出。
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C# POS 小票打印
- C#2.0 print winform 打印窗体数据试试
- [ASP.NET 2.0]定制C#TextBox控件中只允许输入数字的解决方法
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C#2.0 to 4.0
- C#判断一个string是否可以为数字,五种解决方案