❶ 在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