C# winfrom 打印超市类小票

时间:2022-05-12 04:06:44
网上那些源码 没怎么看懂
现在求一个容易懂的。
求大神。 
星期一结贴!。

10 个解决方案

#1


打印不是很简单嘛,你哪里不懂了

#2


都是用第三方组件做的打印,有神马难的?

#3


怎么调用。。
不懂。
从第一步到最后 都不知道做、。

#4


你是那种收银用的小票机?

#5


热敏式打印机~

#6


我自己写了个 不知道对你有用么有
wpf程序的 应该是差不多的
但是wpf是直接打印view的所以我都是直接出图 然后打印的

当时参考这个的好像 这个是winform的吧


int nCount = 0;                      //已打印行数  
            decimal sumMoney = this.m_lstSale[0].MoneySum;  
            long sumNum = 0;  
            for (int i = 1; i < this.m_lstSale.Count; i++)  
            {  
                sumNum += this.m_lstSale[i].SaleNum;  
            }  
            Graphics g = e.Graphics;  
            float fltYPos = 0;                   //每一行的Y坐标  
            float fltXPos = 0;                   //每一行的X坐标  
            float fltLeftMargin = e.MarginBounds.Left;                     //获取打印起始位置  
            float fltTopMargin = e.MarginBounds.Top;  
  
            //=======================表头部分===================================//  
            StringFormat stringFormat = new StringFormat();  
            stringFormat.Alignment = StringAlignment.Center;  
            fltXPos = fltLeftMargin;  
            fltYPos = fltTopMargin;  
            RectangleF rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("欢迎光临", printFont, Brushes.Black, rec, stringFormat);  
            stringFormat.Alignment = StringAlignment.Near;  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("===销售单号:" + m_lstSale[0].AutoID + "==", printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, 80, printFont.GetHeight(e.Graphics));  
            g.DrawString("货号", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos +=80;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width-60, printFont.GetHeight(e.Graphics));  
            g.DrawString("品名", printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            fltXPos -= 30;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString("单价", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString("数量", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
            g.DrawString("金额", printFont, Brushes.Black, rec, stringFormat);  
            //==============================表体部分===========================================  
            //m_lstSale.RemoveAt(0);                                                      //移除表头部分  
            List <Sale> tmpLstSale = new List<Sale>();  
            for (int i = 1; i < m_lstSale.Count; i++)  
            {  
                tmpLstSale .Add (m_lstSale [i]);  
            }  
            while (nCount < tmpLstSale.Count)  
            {  
                Sale sa = tmpLstSale[curLine + nCount];  
                MerchDatum md = sa.MerchDatum;  
                fltXPos = fltLeftMargin;  
                fltYPos += printFont.GetHeight(e.Graphics);  
                rec = new RectangleF(fltXPos, fltYPos,80, printFont.GetHeight(e.Graphics));  
                g.DrawString(md.MerchCode, printFont, Brushes.Black, rec, stringFormat);  
                fltXPos += 80;  
                rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 60, printFont.GetHeight(e.Graphics));  
                g.DrawString(md.MerchName, printFont, Brushes.Black, rec, stringFormat);  
                fltXPos -= 30;  
                fltYPos += printFont.GetHeight(e.Graphics);  
                rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
                g.DrawString(md.SalePrice1.ToString() + "*", printFont, Brushes.Black, rec, stringFormat);  
                fltXPos += 60;  
                rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
                g.DrawString(sa.SaleNum.ToString() + "=", printFont, Brushes.Black, rec, stringFormat);  
                fltXPos += 60;  
                rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
                g.DrawString(Convert.ToString (md.SalePrice1 * sa.SaleNum), printFont, Brushes.Black, rec, stringFormat);  
                nCount++;  
            }  
            fltXPos = fltLeftMargin;  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("====================================", printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            fltXPos += 50;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString("合计:", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString(sumNum.ToString(), printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
            g.DrawString(Generic.GetMoney (sumMoney), printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            fltXPos = fltLeftMargin;  
            rec = new RectangleF(fltXPos, fltYPos, 120, printFont.GetHeight(e.Graphics));  
            g.DrawString("支付:" + Generic.GetMoney (Convert.ToDecimal (this.txtActualPay.Text)), printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 120;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
            g.DrawString("找零:" + Generic.GetMoney(Convert.ToDecimal(this.txtReturn.Text)), printFont, Brushes.Black, rec, stringFormat);  
  
            fltXPos = fltLeftMargin;  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("营业员:"+Program.loginUser , printFont, Brushes.Black, rec, stringFormat);  
  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("--------" + DateTime.Now.ToString() + "--------", printFont, Brushes.Black, rec, stringFormat);  
  
            stringFormat.Alignment = StringAlignment.Center;  
            fltYPos = fltYPos +=2* printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("欢迎再来", printFont, Brushes.Black, rec, stringFormat);  
  
            e.HasMorePages = false;  

#7


打印小票,我觉得Lodop
参考 http://bbs.csdn.net/topics/390199819

#8


C# winfrom 打印超市类小票
我打印的是一个winfrom窗体
数据都在这个窗体中。

#9


该回复于2013-07-13 17:17:25被管理员删除

#10


引用 4 楼 wjbobo 的回复:
你是那种收银用的小票机?

热敏式打印机

#1


打印不是很简单嘛,你哪里不懂了

#2


都是用第三方组件做的打印,有神马难的?

#3


怎么调用。。
不懂。
从第一步到最后 都不知道做、。

#4


你是那种收银用的小票机?

#5


热敏式打印机~

#6


我自己写了个 不知道对你有用么有
wpf程序的 应该是差不多的
但是wpf是直接打印view的所以我都是直接出图 然后打印的

当时参考这个的好像 这个是winform的吧


int nCount = 0;                      //已打印行数  
            decimal sumMoney = this.m_lstSale[0].MoneySum;  
            long sumNum = 0;  
            for (int i = 1; i < this.m_lstSale.Count; i++)  
            {  
                sumNum += this.m_lstSale[i].SaleNum;  
            }  
            Graphics g = e.Graphics;  
            float fltYPos = 0;                   //每一行的Y坐标  
            float fltXPos = 0;                   //每一行的X坐标  
            float fltLeftMargin = e.MarginBounds.Left;                     //获取打印起始位置  
            float fltTopMargin = e.MarginBounds.Top;  
  
            //=======================表头部分===================================//  
            StringFormat stringFormat = new StringFormat();  
            stringFormat.Alignment = StringAlignment.Center;  
            fltXPos = fltLeftMargin;  
            fltYPos = fltTopMargin;  
            RectangleF rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("欢迎光临", printFont, Brushes.Black, rec, stringFormat);  
            stringFormat.Alignment = StringAlignment.Near;  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("===销售单号:" + m_lstSale[0].AutoID + "==", printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, 80, printFont.GetHeight(e.Graphics));  
            g.DrawString("货号", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos +=80;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width-60, printFont.GetHeight(e.Graphics));  
            g.DrawString("品名", printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            fltXPos -= 30;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString("单价", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString("数量", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
            g.DrawString("金额", printFont, Brushes.Black, rec, stringFormat);  
            //==============================表体部分===========================================  
            //m_lstSale.RemoveAt(0);                                                      //移除表头部分  
            List <Sale> tmpLstSale = new List<Sale>();  
            for (int i = 1; i < m_lstSale.Count; i++)  
            {  
                tmpLstSale .Add (m_lstSale [i]);  
            }  
            while (nCount < tmpLstSale.Count)  
            {  
                Sale sa = tmpLstSale[curLine + nCount];  
                MerchDatum md = sa.MerchDatum;  
                fltXPos = fltLeftMargin;  
                fltYPos += printFont.GetHeight(e.Graphics);  
                rec = new RectangleF(fltXPos, fltYPos,80, printFont.GetHeight(e.Graphics));  
                g.DrawString(md.MerchCode, printFont, Brushes.Black, rec, stringFormat);  
                fltXPos += 80;  
                rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 60, printFont.GetHeight(e.Graphics));  
                g.DrawString(md.MerchName, printFont, Brushes.Black, rec, stringFormat);  
                fltXPos -= 30;  
                fltYPos += printFont.GetHeight(e.Graphics);  
                rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
                g.DrawString(md.SalePrice1.ToString() + "*", printFont, Brushes.Black, rec, stringFormat);  
                fltXPos += 60;  
                rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
                g.DrawString(sa.SaleNum.ToString() + "=", printFont, Brushes.Black, rec, stringFormat);  
                fltXPos += 60;  
                rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
                g.DrawString(Convert.ToString (md.SalePrice1 * sa.SaleNum), printFont, Brushes.Black, rec, stringFormat);  
                nCount++;  
            }  
            fltXPos = fltLeftMargin;  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("====================================", printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            fltXPos += 50;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString("合计:", printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));  
            g.DrawString(sumNum.ToString(), printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 60;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
            g.DrawString(Generic.GetMoney (sumMoney), printFont, Brushes.Black, rec, stringFormat);  
            fltYPos += printFont.GetHeight(e.Graphics);  
            fltXPos = fltLeftMargin;  
            rec = new RectangleF(fltXPos, fltYPos, 120, printFont.GetHeight(e.Graphics));  
            g.DrawString("支付:" + Generic.GetMoney (Convert.ToDecimal (this.txtActualPay.Text)), printFont, Brushes.Black, rec, stringFormat);  
            fltXPos += 120;  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));  
            g.DrawString("找零:" + Generic.GetMoney(Convert.ToDecimal(this.txtReturn.Text)), printFont, Brushes.Black, rec, stringFormat);  
  
            fltXPos = fltLeftMargin;  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("营业员:"+Program.loginUser , printFont, Brushes.Black, rec, stringFormat);  
  
            fltYPos += printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("--------" + DateTime.Now.ToString() + "--------", printFont, Brushes.Black, rec, stringFormat);  
  
            stringFormat.Alignment = StringAlignment.Center;  
            fltYPos = fltYPos +=2* printFont.GetHeight(e.Graphics);  
            rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));  
            g.DrawString("欢迎再来", printFont, Brushes.Black, rec, stringFormat);  
  
            e.HasMorePages = false;  

#7


打印小票,我觉得Lodop
参考 http://bbs.csdn.net/topics/390199819

#8


C# winfrom 打印超市类小票
我打印的是一个winfrom窗体
数据都在这个窗体中。

#9


该回复于2013-07-13 17:17:25被管理员删除

#10


引用 4 楼 wjbobo 的回复:
你是那种收银用的小票机?

热敏式打印机