高分求解vb.net 打印的问题
我用vb.net设计了一个准考证打印系统,系统调用数据都很正常的,现在唯一实现不了准考证打印功能,前期用的是printform直接打印窗体,但只能打印出窗体在屏幕显示的部...
我用vb.net 设计了一个准考证打印系统,系统调用数据都很正常的,现在唯一实现不了准考证打印功能,前期用的是printform直接打印窗体,但只能打印出窗体在屏幕显示的部分,准考证必须打印在A4纸,已经折磨了很长时间,不知道有没有其他好方法,用printform能不能实现打印所有内容,或者用报表怎么实现一条数据的打印,而且报表页面要自定义设置版面
展开
1个回答
展开全部
报表打印应该也能实现,但是我觉得你这个用文本打印更简单,将数据输出到txt文件,结果用RichTextBox显示,但是需要简单的排版,调用打印机打印RichTextBox即可的
排版用tab()、space()、&vbcrlf或PrintLine(1)换行,代码类似如下样式
PrintLine(1, TAB(60), "准考证" )
PrintLine(1)
PrintLine(1, "姓名:" & xingming & Space(3) &"准考证号:" & cel(1) & Space(3) & cel(2) & Space(3) & cel(3))
但是TAB()排版比较规整
打印代码类似如下:
PrintDialog1.Document = PrintDocument1
PrintDocument1.DocumentName = "准考证"
PrintDialog1.AllowSomePages = False
PrintDialog1.ShowHelp = False
PrintDialog1.ShowNetwork = False
PrintDialog1.AllowSelection = False
PrintDialog1.AllowPrintToFile = False
MySReader = New StringReader(RichTextBox1.Text)
stringToPrint = MySReader.ReadToEnd()
PageSetupDialog1.Document = PrintDocument1
PageSetupDialog1.PageSettings.Margins.Bottom = 50
PageSetupDialog1.PageSettings.Margins.Top = 50
PageSetupDialog1.PageSettings.Margins.Left = 50
PageSetupDialog1.PageSettings.Margins.Right = 50
If PageSetupDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings '页面设置
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
If PrintDialog1.PrinterSettings.IsValid = True Then
PrintDocument1.Print()
MsgBox("打印完成!" & vbCrLf & "Print completed!", , "Print hint(打印提示)")
Else
MsgBox("打印失败!打印机不可用。" & vbCrLf & "Print failed! The printer is not valid.", , "Print hint(打印提示)")
End If
Else
Exit Sub
End If
End If
排版用tab()、space()、&vbcrlf或PrintLine(1)换行,代码类似如下样式
PrintLine(1, TAB(60), "准考证" )
PrintLine(1)
PrintLine(1, "姓名:" & xingming & Space(3) &"准考证号:" & cel(1) & Space(3) & cel(2) & Space(3) & cel(3))
但是TAB()排版比较规整
打印代码类似如下:
PrintDialog1.Document = PrintDocument1
PrintDocument1.DocumentName = "准考证"
PrintDialog1.AllowSomePages = False
PrintDialog1.ShowHelp = False
PrintDialog1.ShowNetwork = False
PrintDialog1.AllowSelection = False
PrintDialog1.AllowPrintToFile = False
MySReader = New StringReader(RichTextBox1.Text)
stringToPrint = MySReader.ReadToEnd()
PageSetupDialog1.Document = PrintDocument1
PageSetupDialog1.PageSettings.Margins.Bottom = 50
PageSetupDialog1.PageSettings.Margins.Top = 50
PageSetupDialog1.PageSettings.Margins.Left = 50
PageSetupDialog1.PageSettings.Margins.Right = 50
If PageSetupDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings '页面设置
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
If PrintDialog1.PrinterSettings.IsValid = True Then
PrintDocument1.Print()
MsgBox("打印完成!" & vbCrLf & "Print completed!", , "Print hint(打印提示)")
Else
MsgBox("打印失败!打印机不可用。" & vbCrLf & "Print failed! The printer is not valid.", , "Print hint(打印提示)")
End If
Else
Exit Sub
End If
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询