VB怎么实现打印功能

2024-12-23 11:44:09
推荐回答(3个)
回答1:

从应用程序中打印
Visual Basic 为打印正文和图形提供了三种技术。
可在窗体中建立所需要的输出,然后用 PrintForm 方法打印窗体。
Private Sub Command1_Click()
Me.PrintForm
End Sub

通过设置 Printers 集合中的缺省的打印机,可传送正文和图形到打印机。
...

可先传送正文和图形给 Printer 对象,再用 NewPage 和 EndDoc 方法打印。

Option Explicit
Private y As Integer
Private x As Integer
Private txt As String
Private fnt As Integer
Private dd As Variant
'打印函数
Public Function prnt(x As Variant, y As Variant, fnt As Variant, txt As Variant)
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = fnt
Printer.Print txt
End Function

Private Sub cmdPrint_Click()
fnt = 18
y = 300
x = 500
txt = "打印"
dd = prnt(x, y, fnt, txt)
Printer.EndDoc ' 打印完成。
End Sub
其它如数据查询等请参阅如下网址:
http://zhidao.baidu.com/question/4168806.html

回答2:

方法:传送正文和图形给 Printer 对象,再用 NewPage 和 EndDoc 方法打印。,代码如下:

Option Explicit
Private y As Integer
Private x As Integer
Private txt As String
Private fnt As Integer
Private dd As Variant
'打印函数
Public Function prnt(x As Variant, y As Variant, fnt As Variant, txt As Variant)
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = fnt
Printer.Print txt
End Function

Private Sub cmdPrint_Click()
fnt = 18
y = 300
x = 500
txt = "打印"
dd = prnt(x, y, fnt, txt)
Printer.EndDoc ' 打印完成。
End Sub

回答3:

vb 打印比较麻烦。可以第三方控件。其实vb也自带了打印功能。就是那个报表设计器。很难用。