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(40404040);
 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, 152505);
 74            //
 75            e.Graphics.DrawString("欢迎光临缔友书城南山城", font, brush, 4555);
 76           //
 77            e.Graphics.DrawString("若有质量问题三日内凭票退换", font, brush, 4070);
 78            //
 79            e.Graphics.DrawString("95925", font, brush, 185);
 80            e.Graphics.DrawString("#20000000372", font, brush, 25085, sf);
 81            //名称,单价,数量,金额
 82            e.Graphics.DrawString("名称", font, brush, 1100);
 83            e.Graphics.DrawString("单价", font, brush, 60100);
 84            e.Graphics.DrawString("数量", font, brush, 120100);
 85            e.Graphics.DrawString("金额", font, brush, 220100);
 86            //1
 87            e.Graphics.DrawString("装订夹", font, brush, 1115);
 88            e.Graphics.DrawString("19.00", font, brush, 60115);
 89            e.Graphics.DrawString("200", font, brush, 120115);
 90            e.Graphics.DrawString("3800", font, brush, 250115, sf);
 91            //2
 92            e.Graphics.DrawString("不锈钢夹", font, brush, 1130);
 93            e.Graphics.DrawString("98.00", font, brush, 60130);
 94            e.Graphics.DrawString("90", font, brush, 120130);
 95            e.Graphics.DrawString("8820.00", font, brush, 250130, sf);
 96            //3
 97            e.Graphics.DrawString("固体胶", font, brush, 1145);
 98            e.Graphics.DrawString("18.50", font, brush, 60145);
 99            e.Graphics.DrawString("60", font, brush, 120145);
100            e.Graphics.DrawString("1110.00", font, brush, 250145, sf);
101            //4
102            e.Graphics.DrawString("档案盒", font, brush, 1160);
103            e.Graphics.DrawString("4.80", font, brush, 60160);
104            e.Graphics.DrawString("265", font, brush, 120160);
105            e.Graphics.DrawString("1272", font, brush, 250160, sf);
106            //划虚线
107            //Pen ftqGoal = new Pen(Color.Black, 1);
108            //ftqGoal.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
109            e.Graphics.DrawLine(ftqGoal, 1182250182);
110            //小计
111            e.Graphics.DrawString("(小计)", font, brush, 1190);
112            e.Graphics.DrawString("4项", font, brush, 60190);
113            e.Graphics.DrawString("615件", font, brush, 120190);
114            e.Graphics.DrawString("15000.00", font, brush, 250190, sf);
115            //实收
116            e.Graphics.DrawString("实收", font, brush, 1205);
117            e.Graphics.DrawString("15000.00", font, brush, 250205, sf);
118            //找回
119            e.Graphics.DrawString("找回", font, brush, 1220);
120            e.Graphics.DrawString("0.00", font, brush, 250220, sf);
121            //划虚线
122           // Pen ftqGoal = new Pen(Color.Black, 1);
123            //ftqGoal.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
124            e.Graphics.DrawLine(ftqGoal, 1242250242);
125            //
126            e.Graphics.DrawString("2503", font, brush, 1250);
127            e.Graphics.DrawString("2008年11月19日  10:48", font, brush, 250250, sf);
128            //
129            e.Graphics.DrawString("一次消费满50元,免费停车2小时(当日有效)", font, brush, 1265);
130            //
131            e.Graphics.DrawString("免费停车票到一楼总服务台领取", font, brush, 25280);
132            //
133            e.Graphics.DrawString("WWW.DUPCIT.COM 客户服务热线:86369385", font, brush, 1295);
134
135        }

136    }

137}
原文地址:https://www.cnblogs.com/geovindu/p/1498361.html