大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
先拖过来控件PrintDocument1,然后双击PrintDocument1,在它的PrintPage事件中加入代码如下:
我们提供的服务有:网站建设、做网站、微信公众号开发、网站优化、网站认证、禹王台ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的禹王台网站制作公司
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
dim a as String
a="abcd"
Dim mypen As Pen = New Pen(Color.Blue, 2)
e.Graphics.DrawString(a, New Font("宋体", 20), New Pen(Color.Black, 1).Brush, 30, 30)
End Sub
调用下面语句可直接用默认打印机打印出来:
PrintDocument1.Print()
毫无疑问,被窗口拦截工具拦截了。浏览器没有设置,Google 工具条呢,3721呢,MSN工具条呢,这些号称可以禁止垃圾信息的垃圾工具都可能导致弹出窗口消失。
Sub Macro1()
'
' Macro1 Macro
' 宏在 10-02-04 由 user 录制
'
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
报表打印应该也能实现,但是我觉得你这个用文本打印更简单,将数据输出到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