VB窗体打印求解,为啥会打出奇怪的符号?
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询