积极答复者
求救!关于vb2008打印问题

问题
-
求救!关于vb2008打印问题,准备用针式打印机后进纸打印一个销售列表格式如下
XXX标题
========================================================
名称 数量 单位 地址 备注
--------------------------------------------------------
xxx 2 1 xxxx xxxx
xxx 2 1 xxxx xxxx
.......
========================================================
原来在vb6中可以用printr.print语句实现,现在在vb2008中不可以,希望给出思路和代码,我是新学,请说的简单点具体点,求指点,谢谢
- 已编辑 文雨 2011年7月25日 1:20 格式修改
答案
-
我这正好有一段VB。net中用printdocument来打印文件的一段代码,希望可以帮到你:
Public Sub PrintFile(fileName As String) Dim pd As New PrintDocument pd.DefaultPageSettings.Margins = New Margins(25, 25, 50, 50) arrFile = IO.File.ReadAllLines(fileName) AddHandler pd.PrintPage, AddressOf HowToPrint pd.Print() End Sub Private i As Integer = 0 Private pages As Integer = 0 Private arrFile() As String Private Sub HowToPrint(sender As Object, e As PrintPageEventArgs) While i < arrFile.Length e.Graphics.DrawString(arrFile(i), New Font("Calibri", 10.2), Brushes.Black, New Point(10, i * 13 - pages * 70 * 13 + 26)) i += 1 'each page per 70 lines If i Mod 70 = 0 Then e.HasMorePages = True pages += 1 Exit Sub End If End While e.HasMorePages = False arrFile = Nothing End Sub
数据都是一样的打印。
Best regards,
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年8月5日 8:51
全部回复
-
我这正好有一段VB。net中用printdocument来打印文件的一段代码,希望可以帮到你:
Public Sub PrintFile(fileName As String) Dim pd As New PrintDocument pd.DefaultPageSettings.Margins = New Margins(25, 25, 50, 50) arrFile = IO.File.ReadAllLines(fileName) AddHandler pd.PrintPage, AddressOf HowToPrint pd.Print() End Sub Private i As Integer = 0 Private pages As Integer = 0 Private arrFile() As String Private Sub HowToPrint(sender As Object, e As PrintPageEventArgs) While i < arrFile.Length e.Graphics.DrawString(arrFile(i), New Font("Calibri", 10.2), Brushes.Black, New Point(10, i * 13 - pages * 70 * 13 + 26)) i += 1 'each page per 70 lines If i Mod 70 = 0 Then e.HasMorePages = True pages += 1 Exit Sub End If End While e.HasMorePages = False arrFile = Nothing End Sub
数据都是一样的打印。
Best regards,
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年8月5日 8:51