printDocument,到调用的时候,最后几行就不换行了,麻烦高手给看一下
------------------打印类-------------------------------------
Imports System.Drawing
Imports System.Drawing.PrintingPublic Class clsPrint
'---定义全局变量----
Public Shared sPrintContent As String '要打印的内容(指待打印的小票内容) ''' <summary>
''' 用指定的打印机打印小票()
''' </summary>
''' 待扩展:上下左右的边界可由设置,纸张大小可设置
''' <param name="DYJMC">打印机名称</param>
''' <res></res>
Public Shared Sub A_pPrint(ByVal DYJMC As String)
Dim OK As Boolean = False 'Dim PPD As PrintPreviewDialog = New PrintPreviewDialog()'打印预览
Dim Pd As PrintDocument = New PrintDocument()
'--------判断该打印机是否存在---------
Dim DYJ As PrinterSettings.StringCollection = PrinterSettings.InstalledPrinters
For Each s In DYJ
If s = DYJMC Then
OK = True
Exit For
End If
Next If OK Then '如果指定的打印机存在,则用该打印机,否则用默认打印机
Pd.PrinterSettings.PrinterName = DYJMC '
End If '设置边距
Dim MARGIN As Margins = New Margins(2, 1, 2, 1)
Pd.DefaultPageSettings.Margins = MARGIN
'纸张设置默认
'Dim pageSize As PaperSize = New PaperSize("First custom size", getWidth(58), 1700)
'Pd.DefaultPageSettings.PaperSize = pageSize '打印事件设置
AddHandler Pd.PrintPage, AddressOf pd_PrintPage '打印预览
'PPD.Document = PD
'ppd.ShowDialog(me)
Try
Pd.Print()
Catch ex As Exception
MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error)
Pd.PrintController.OnEndPrint(Pd, New PrintEventArgs())
End Try End Sub '获取宽度
Public Shared Function getWidth(ByVal cm As Double) As Integer
Return CInt(cm / 25.4) * 100
End Function '添加自定义事件
Public Shared Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim printerHDC As IntPtr = ev.Graphics.GetHdc()
Dim g As Graphics = Graphics.FromHdc(printerHDC)
g.DrawString(sPrintContent, New Font("宋体", 9), Brushes.Red, New PointF(0, 0))
End SubEnd Class
-------------------调用类,开始打印的代码---------------------------------- Private Sub print()
Dim sTMP As String = ""
Dim ZJE As Decimal = 0
'--------增加单号信息-------------
sTMP = gSysInfo.sMDMC + "班报" + Chr(13) + Chr(10)
sTMP += "班 号:" + DQBH + " 第" + DQBC + "班" + Chr(13) + Chr(10)
sTMP += "收 银 员:" + gUserInfo.sUserId + " 收款机号:" + gSysInfo.sDQSYJ + Chr(13) + Chr(10)
sTMP += "前班余额:" + lbQXYE.Text + " 销售额:" + lbYYE.Text + Chr(13) + Chr(10)
sTMP += "本班实收:" + lbBBSSJE.Text + " 折扣额:" + lbZKJE.Text + Chr(13) + Chr(10)
sTMP += "现 金:" + lbXJ.Text + " 刷卡:" + lbSK.Text + Chr(13) + Chr(10)
sTMP += "钱箱余额:" + lbBBQXYE.Text + " 抵用券:" + lbDYQ.Text + Chr(13) + Chr(10)
sTMP += "当班时间:" + lbKSSJ.Text + Chr(13) + Chr(10) '开始时间
sTMP += " " + lbJSSJ.Text + Chr(13) + Chr(10) '结束时间
sTMP += "打印时间:" + Now.ToString + Chr(13) + Chr(10)
sTMP += "------------------------------" + Chr(13) + Chr(10)
sTMP += "[收银明细]" + Chr(13) + Chr(10)
sTMP += "营业员 现金 刷卡 抵用券 合计" + Chr(13) + Chr(10)
'---按营业员分组的收款明细------------------
Sql = "Select Isnull(YWY,'公共') As YWY ,Isnull(Sum(JE),0) As JE,Isnull(Sum(SSJE),0) As SSJE,Isnull(Sum(XJ),0) As XJ,Isnull(Sum(SK),0) As SK,Isnull(Sum(QTJE),0) As QTJE,Isnull(Sum(MLJE),0) As MLJE From POS_T_XSCKD Where DQBH ='" + DQBH + "' Group By YWY " '用班单号做为统计条件,可解决深夜12点以后的销售统计问题
If Not MyDataWork.ExecSelect(dt, Sql, "") Then
For i = 0 To dt.Rows.Count - 1
sTMP += dt.Rows(i)("YWY").ToString + " " + dt.Rows(i)("XJ").ToString + " " + dt.Rows(i)("SK").ToString + " " + Format(Math.Round(dt.Rows(i)("QTJE") * 100) / 100, "#0.00") + " " + Format(Math.Round(dt.Rows(i)("SSJE") * 100) / 100, "#0.00") + Chr(13) + Chr(10)
ZJE += Math.Round(dt.Rows(i)("SSJE") * 100) / 100
Next
End If
sTMP += "** 合计:" + Format(ZJE, "#0.00") + Chr(13) + Chr(10)
sTMP += "-----------------------" + Chr(13) + Chr(10)
sTMP += "存现金额:" + Chr(13) + Chr(10)
sTMP += "存现日期: 签字:" + Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10) '------空行--------
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
clsPrint.sPrintContent = sTMP
clsPrint.A_pPrint(gSysInfo.sDYJDK) '打印机名称
'Return sTMP
End Sub
-----------------
打印出来的结果,就是只打印到“存现金额”那一行,下面的就不打不出来了,麻烦做过的童鞋给看一下,谢谢啦!
------------------打印类-------------------------------------
Imports System.Drawing
Imports System.Drawing.PrintingPublic Class clsPrint
'---定义全局变量----
Public Shared sPrintContent As String '要打印的内容(指待打印的小票内容) ''' <summary>
''' 用指定的打印机打印小票()
''' </summary>
''' 待扩展:上下左右的边界可由设置,纸张大小可设置
''' <param name="DYJMC">打印机名称</param>
''' <res></res>
Public Shared Sub A_pPrint(ByVal DYJMC As String)
Dim OK As Boolean = False 'Dim PPD As PrintPreviewDialog = New PrintPreviewDialog()'打印预览
Dim Pd As PrintDocument = New PrintDocument()
'--------判断该打印机是否存在---------
Dim DYJ As PrinterSettings.StringCollection = PrinterSettings.InstalledPrinters
For Each s In DYJ
If s = DYJMC Then
OK = True
Exit For
End If
Next If OK Then '如果指定的打印机存在,则用该打印机,否则用默认打印机
Pd.PrinterSettings.PrinterName = DYJMC '
End If '设置边距
Dim MARGIN As Margins = New Margins(2, 1, 2, 1)
Pd.DefaultPageSettings.Margins = MARGIN
'纸张设置默认
'Dim pageSize As PaperSize = New PaperSize("First custom size", getWidth(58), 1700)
'Pd.DefaultPageSettings.PaperSize = pageSize '打印事件设置
AddHandler Pd.PrintPage, AddressOf pd_PrintPage '打印预览
'PPD.Document = PD
'ppd.ShowDialog(me)
Try
Pd.Print()
Catch ex As Exception
MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error)
Pd.PrintController.OnEndPrint(Pd, New PrintEventArgs())
End Try End Sub '获取宽度
Public Shared Function getWidth(ByVal cm As Double) As Integer
Return CInt(cm / 25.4) * 100
End Function '添加自定义事件
Public Shared Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim printerHDC As IntPtr = ev.Graphics.GetHdc()
Dim g As Graphics = Graphics.FromHdc(printerHDC)
g.DrawString(sPrintContent, New Font("宋体", 9), Brushes.Red, New PointF(0, 0))
End SubEnd Class
-------------------调用类,开始打印的代码---------------------------------- Private Sub print()
Dim sTMP As String = ""
Dim ZJE As Decimal = 0
'--------增加单号信息-------------
sTMP = gSysInfo.sMDMC + "班报" + Chr(13) + Chr(10)
sTMP += "班 号:" + DQBH + " 第" + DQBC + "班" + Chr(13) + Chr(10)
sTMP += "收 银 员:" + gUserInfo.sUserId + " 收款机号:" + gSysInfo.sDQSYJ + Chr(13) + Chr(10)
sTMP += "前班余额:" + lbQXYE.Text + " 销售额:" + lbYYE.Text + Chr(13) + Chr(10)
sTMP += "本班实收:" + lbBBSSJE.Text + " 折扣额:" + lbZKJE.Text + Chr(13) + Chr(10)
sTMP += "现 金:" + lbXJ.Text + " 刷卡:" + lbSK.Text + Chr(13) + Chr(10)
sTMP += "钱箱余额:" + lbBBQXYE.Text + " 抵用券:" + lbDYQ.Text + Chr(13) + Chr(10)
sTMP += "当班时间:" + lbKSSJ.Text + Chr(13) + Chr(10) '开始时间
sTMP += " " + lbJSSJ.Text + Chr(13) + Chr(10) '结束时间
sTMP += "打印时间:" + Now.ToString + Chr(13) + Chr(10)
sTMP += "------------------------------" + Chr(13) + Chr(10)
sTMP += "[收银明细]" + Chr(13) + Chr(10)
sTMP += "营业员 现金 刷卡 抵用券 合计" + Chr(13) + Chr(10)
'---按营业员分组的收款明细------------------
Sql = "Select Isnull(YWY,'公共') As YWY ,Isnull(Sum(JE),0) As JE,Isnull(Sum(SSJE),0) As SSJE,Isnull(Sum(XJ),0) As XJ,Isnull(Sum(SK),0) As SK,Isnull(Sum(QTJE),0) As QTJE,Isnull(Sum(MLJE),0) As MLJE From POS_T_XSCKD Where DQBH ='" + DQBH + "' Group By YWY " '用班单号做为统计条件,可解决深夜12点以后的销售统计问题
If Not MyDataWork.ExecSelect(dt, Sql, "") Then
For i = 0 To dt.Rows.Count - 1
sTMP += dt.Rows(i)("YWY").ToString + " " + dt.Rows(i)("XJ").ToString + " " + dt.Rows(i)("SK").ToString + " " + Format(Math.Round(dt.Rows(i)("QTJE") * 100) / 100, "#0.00") + " " + Format(Math.Round(dt.Rows(i)("SSJE") * 100) / 100, "#0.00") + Chr(13) + Chr(10)
ZJE += Math.Round(dt.Rows(i)("SSJE") * 100) / 100
Next
End If
sTMP += "** 合计:" + Format(ZJE, "#0.00") + Chr(13) + Chr(10)
sTMP += "-----------------------" + Chr(13) + Chr(10)
sTMP += "存现金额:" + Chr(13) + Chr(10)
sTMP += "存现日期: 签字:" + Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10) '------空行--------
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
sTMP += Chr(13) + Chr(10)
clsPrint.sPrintContent = sTMP
clsPrint.A_pPrint(gSysInfo.sDYJDK) '打印机名称
'Return sTMP
End Sub
-----------------
打印出来的结果,就是只打印到“存现金额”那一行,下面的就不打不出来了,麻烦做过的童鞋给看一下,谢谢啦!
解决方案 »
- C# ValidateNull中怎么使用
- 送分了。
- 输出字节缓冲区太小,无法包含编码后的数据,编码“简体中文(GB2312)”的操作回退“System.Text.InternalEncoderBestFitFal
- DLL反编译成CS后再编译回成DLL
- C# 存数据进数据库 问题处在哪里了!?
- WebClient.DownloadFile()越来越慢
- 关于datagrid的问题,望高手指点!
- 请大家推荐一本学习DirectX 3D 编程的入门书!
- 如何扫描文件夹?
- 急贴,大侠们帮忙!DropDownList在火狐可以获取选定值,在IE8不可以,为什么!!!!
- Dos 命令
- (求助)c# 中 单个& 和| 是什么操作啊?
换成 "\r\n"试试to 2L 可以实现
网上说 createfile 只适用于 . lpt com 。
USB 是属于 虚拟接口所以并不能使用 这个老式的 方法.
但是我在网站找了好多方法都使用不上哦。 都说要调用驱动。(我不知道怎么调用驱动)
然后我使用 printdocument print() 就弹出了打印设置窗口才可以打印。
请问 要用什么方法才可以 直接打印呢?
PrintDocument pd = new PrintDocument();
PaperSize ps = new PaperSize("xxx", 350, 650);
pd.DefaultPageSettings.PaperSize = ps;
pd.DefaultPageSettings.PrinterSettings.Copies = 1;
pd.DefaultPageSettings.PrinterSettings.MaximumPage = 1;
NT,2000,XP,2003....下不能用DefaultPageSettings.PaperSize = new PaperSize("Custom", 826, 492)这种方式定义纸张大小,Win98才可以呢??http://topic.csdn.net/u/20100831/20/4d15e4cd-40f5-403b-8090-c8c9e7dee1de.html