❶ 在VB中如何实现打印的功能
Printer对象
Printer对象可以实现与系统打印机的通信
Printer对象常用的属性有:Height,width,PaperSize,DeviceName等分别表示打印纸的长度,宽度,纸张大小,打印机名称。
Printer对象有三个很重要的方法:EndDoc(开始打印),KillDoc(中断打印)和NewPage(换页).
例如:有一个“注意26日病毒!”提示要打印10份,并加页码,用如下程序段实现:
Private Sub command_Click()
Dim i As Integer
Dim str As String
str="注意26日病毒!"
Printer.FontName="黑体"
Printer.FontSize=26
For i=1 To 10
Printer.Print str
Printer.Print "第 " & Printer.Page & "页"
Printer.NewPage
Next
Printer.EndDoc
End Sub
❷ VB打印的代码如下图
用VB可以直接使用对象 Printer 进行数据及图片的打印。
如:
'***初始化打印机
Printer.ScaleMode = 1
Printer.FontName = "仿宋_GB2312"
Printer.FontSize = 8
Printer.FontBold = False
'设置打印区域,四个 参数分别是打印区域的左上角及右下角坐标
' 这里以 A4 打印纸张大小为例,边框距各为2cm.
PrtLeftx=567*2
PrtLefty=567*2.0
PrtRightx=567*(21-2)
PrtLefty=567*(29.5-2)
'**打印线条
Printer.DrawWidth = 2
Printer.Line (PrtLeftx, PrtLefty)-(PrtRightx, PrtLefty)
Printer.DrawWidth = 1
' 打印字符串
Printer.Print "中国 China"
要打印窗体中TextBox 中的内容,将其赋给变量或直接打印都可以。
❸ 求"打印"的VB代码!
是本人关于数据库查询输出的代码,可供参考:
VB下数据报表打印输出方法有多种,一是通过自己的设计和编程完成报表打印输出。二是通过MS OFFICE实现报表打印输出。三是应用数据报表设计器的报表打印输出。本人经常使用第一种方法,它具有根据需要灵活应用的特点,但需编写程序。下附代码,第一段代码定义基本变量,第二段代码定义打印函数,第三段代码是具体打印代码,含数据转换。第四段代码是窗体加载代码,具体连接数据库和打印代码根据你所涉及的数据要求进行修改。
Option Explicit
Private n As Integer
Private m As Integer
Private zh_dm(10) As Double
Private dy_dm(3000, 10) As Variant
Private zsl As Integer
Private y As Integer
Private x As Integer
Private i As Integer
Private k As Integer
Private p As Integer
Private pa As Integer
Private j 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, txt0 As Variant)
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = fnt
Printer.Print txt0
End Function
Private Sub cmdPrint_Click()
Adodc1.Recordset.MoveFirst
For i = 0 To zsl - 1
For j = 0 To 7
dy_dm(i, j) = Adodc1.Recordset(j)
Next j
Adodc1.Recordset.MoveNext
Next i
'确定页数
k = Int(zsl / 80)'80为每页行数
If k - zsl / 80 < 0 Then
k = k + 1
End If
fnt = 8
For p = 0 To k - 1
pa = p + 1
y = 300
x = 4500
txt = "机物料库存"
dd = prnt(x, y, fnt, txt)
x = 8500
txt = "第" & p + 1 & "页"
dd = prnt(x, y, fnt, txt)
y = 500
x = 600
txt = "备件代码"
dd = prnt(x, y, fnt, txt)
x = 1500
txt = "备件名称"
dd = prnt(x, y, fnt, txt)
x = 3500
txt = "备件规格"
dd = prnt(x, y, fnt, txt)
x = 5500
txt = "进口计算机号"
dd = prnt(x, y, fnt, txt)
x = 7500
txt = "最低储备量"
dd = prnt(x, y, fnt, txt)
x = 9000
txt = "库存量"
dd = prnt(x, y, fnt, txt)
For i = 0 + p * 80 To 79 + p * 80
y = 700 + 180 * (i - p * 80)
x = 600
txt = dy_dm(i, 1)
dd = prnt(x, y, fnt, txt)
x = 1500
txt = dy_dm(i, 2)
dd = prnt(x, y, fnt, txt)
x = 3500
txt = dy_dm(i, 3)
dd = prnt(x, y, fnt, txt)
x = 5500
txt = dy_dm(i, 4)
dd = prnt(x, y, fnt, txt)
x = 7500
txt = dy_dm(i, 5)
dd = prnt(x, y, fnt, txt)
x = 9000
txt = dy_dm(i, 6)
dd = prnt(x, y, fnt, txt)
'打印分隔线条
If Int(i / 10) - i / 10 = 0 Then
Printer.Line (500, 695 + (i - p * 80) * 180)-(10000, 695 + (i - p * 80) * 180)
End If
Next i
If zsl - p * 80 > 80 Then
Printer.Line (500, 695 + 180 * 80)-(10000, 695 + 180 * 80)
Printer.NewPage
End If
Next p
Printer.EndDoc ' 打印完成。
Cls
End Sub
'查询代码
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc1.RecordSource = "select cs.js_dm,cs.备件代码,cs.备件名称,cs.备件规格,cs.进口计算机号,cs.最低库存量,sl.结存数量,sl.结存金额,sl.结存单价,sl.类别代码 from JWCK_BM as cs,jwl_jiec as sl" & _
" where cs.备件代码 = sl.备件代码" & " and cs.备件代码>" & "''" & " order by sl.类别代码,sl.备件代码"
Adodc1.Refresh
DataGrid1.Refresh
zsl = Adodc1.Recordset.RecordCount
Adodc3.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc3.RecordSource = "select sum(结存金额) as hj from jwl_jiec"
Adodc3.Refresh
End Sub
以上供参考。其它请参考西安交通大学出版社出版的“VISUAL BASIC 6.0 高级编程技巧-ADO数据访问篇“
❹ vb中的打印代码
最简单的,就是:
Me.PrintForm
否则,一两句话还说不清。
错误肯定是严重的!专
For i = 0 To DataGrid1 - 1
你这个 DataGrid1 叫系统怎么理解?属DataGrid1是这个网格控件的名字对吧?名字还可以减1啊?那么名字减1等于几呢?
你要这样打印结果的话,我告诉你要这样:DataGrid控件有列属性(Col)和行属性(Row),这样就可以获得某单元格的内容了:这样:
要定位到列和行,才能获得指定的单元格值:并且注意,行与列号都是从0开始编号!
DataGrid1.Col = 0
DataGrid1.Row = 0
Print DataGrid1.Text '这样就能获得首行首列单元格的内容
所以要获得全部内容,要使用循环。
但是,换个思路,你这个DataGrid控件里的数据,应该来自于记录集对象,那直接用对象的属性来获得就可以了呀!
❺ VB怎么实现打印功能
从应用程序中打印
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://..com/question/4168806.html