C#2.0 数字“0”是有一道斜线,打印虚线,Pos打印
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Drawing.Drawing2D;
7using System.Text;
8using System.Windows.Forms;
9using System.Data.SqlClient;
10using System.Drawing.Printing;
11
12namespace 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}
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Drawing.Drawing2D;
7using System.Text;
8using System.Windows.Forms;
9using System.Data.SqlClient;
10using System.Drawing.Printing;
11
12namespace 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}
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)