十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
使用 PrintDocument 控件的 Print() 方法可以打印指定對象中的內容,參考代碼如下:
成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于成都網(wǎng)站設計、成都網(wǎng)站建設、嘉蔭網(wǎng)絡推廣、小程序開發(fā)、嘉蔭網(wǎng)絡營銷、嘉蔭企業(yè)策劃、嘉蔭品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供嘉蔭建站搭建服務,24小時服務熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
PrintDocument1.Print()
End?Sub
Private?Sub?PrintDocument1_PrintPage(ByVal?sender?As?System.Object,?ByVal?e?As?System.Drawing.Printing.PrintPageEventArgs)?Handles?PrintDocument1.PrintPage
Dim?bm?As?New?Bitmap(Me.DataGridView1.Width,?Me.DataGridView1.Height)
DataGridView1.DrawToBitmap(bm,?New?Rectangle(0,?0,?Me.DataGridView1.Width,?Me.DataGridView1.Height))
e.Graphics.DrawImage(bm,?0,?0)
End?Sub
txt文件:
procedure TForm1.Button1Click(Sender: TObject);
var
MyFile: TextFile;
SourceFile:TextFile;
Tmp:String;
begin
AssignPrn(MyFile);
AssignFile(SourceFile,'FilePath');
Reset(SourceFile);
Rewrite(MyFile);
Readln(SourceFile,Tmp);
While Not EOF(SourceFile) do
Begin
Writeln(MyFile, Tmp);
Readln(SourceFile,Tmp);
System.CloseFile(MyFile);
end;
圖形文件需要TPrinter.canvas來打印了,
可以把數(shù)據(jù)導出到EXCEL,然后使用EXCEL進一步處理后使用。
也可以做成vb報表(VB自帶有)。
先設置報表格式,打印時向報表傳遞數(shù)據(jù)就可以了。
有個PrintDocument控件,可以實現(xiàn)打印。。。
MSDN原話:
使用 PrintDocument 組件
涉及 PrintDocument 組件的兩種主要情況是:
簡單的打印作業(yè),如打印單個文本文件。在這種情況下,應將 PrintDocument 組件添加到 Windows 窗體,然后在 PrintPage 事件處理程序中添加打印文件的編程邏輯。 該編程邏輯應以使用 Print 方法打印文檔結束。
此方法向打印機發(fā)送一個 Graphics 對象,該對象包含在 PrintPageEventArgs 類的 Graphics 屬性中。
有關如何使用 PrintDocument 組件打印文本文檔的示例,請參見
如何:打印 Windows 窗體中的多頁文本文件。
更為復雜的打印作業(yè),如想要重新使用已編寫的打印邏輯的情況。
在這種情況下,應從 PrintDocument 組件派生一個新組件,并重寫
(請參見 Visual Basic 的 重寫或 C# 的 重寫) PrintPage 事件。
將 PrintDocument 組件添加到窗體后,它出現(xiàn)在 Windows 窗體設計器底部的欄中
利用 printdocument控件
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim stringFont As New Font("Arial", 16)
Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
Dim strFormat As New StringFormat
Dim s As String
s = "print word" '打印的內容
e.Graphics.DrawString(s, stringFont, Brushes.AliceBlue, rectDraw, strFormat)
End Sub
參考:
把執(zhí)行SQL語句后得到的記錄集逐條(含字段名)顯示在LISTVIEW控件中
'----------------------------------------------------------------
Public Sub ListUpdate(ByRef rs As Recordset, ByRef lv As ListView)
Dim head As ColumnHeader, Item As ListItem
Dim i As Integer, j As Integer
Dim lvWidth As Integer
lvWidth = lv.Width
'初始化LISTVIEW的某些屬性
lv.View = lvwReport
lv.GridLines = True
lv.FullRowSelect = True
lv.ListItems.Clear
lv.ColumnHeaders.Clear
For i = 0 To rs.Fields.Count - 1
Set head = lv.ColumnHeaders.Add
head.Text = rs.Fields(i).Name
head.Width = lvWidth / rs.Fields.Count
Next
For j = 1 To PERPAGE
If rs.EOF Then Exit For
Set Item = lv.ListItems.Add
Item.Text = "" rs.Fields(0).Value
For i = 1 To rs.Fields.Count - 1
Item.SubItems(i) = "" rs.Fields(i).Value
Next
rs.MoveNext
Next
End Sub
' 打印
Public Sub PrintRecordset(ByRef recRecordset As Recordset, ByVal strType As String)
Dim LeftMargin As Integer
Dim HeadTopPosition As Integer
Dim FieldNum As Integer
Dim PageCounter As Integer
Dim MyRecordset As ADODB.Recordset
Const FooterTopPosition = 24
Set MyRecordset = recRecordset
PageCounter = 1
' 設 置Printer 對 象 坐 標 的 度 量 單 位 為 厘 米
Printer.ScaleMode = vbCentimeters
LeftMargin = 1.5
HeadTopPosition = 2
' 定 義 打 印 頁 左 上 角 的X 坐 標 和Y 坐 標, 通 過 改 變ScaleLeft 和ScaleTop 的 值, 可 改 變 打 印 頁 的 左 邊 距 和 上 邊 距
Printer.ScaleLeft = -LeftMargin
Printer.ScaleTop = -HeadTopPosition
Printer.Font.Name = "Times New Roman"
Printer.Font.Size = 12
Printer.Print "音像店顧客管理系統(tǒng)"
Printer.Print strType
Printer.Print ""
If MyRecordset.EOF And MyRecordset.BOF Then
MsgBox "No Record At Presend!", vbCritical And vbOKOnly, "Print Error"
Exit Sub
End If
MyRecordset.MoveFirst
Do Until Printer.CurrentY FooterTopPosition
'Print the fields of the recordset in sequence
For FieldNum = 0 To MyRecordset.Fields.Count - 1
Printer.Print MyRecordset.Fields(FieldNum).Name _
": " _
MyRecordset.Fields(FieldNum).Value
If Printer.CurrentY FooterTopPosition Then
Printer.CurrentX = 8
Printer.Print "Page: " PageCounter
' 創(chuàng) 建 多 頁 文 檔
Printer.NewPage
PageCounter = PageCounter + 1
End If
Next FieldNum
MyRecordset.MoveNext
If MyRecordset.EOF Then Exit Do
' 在 記 錄 之 間 空 一 行
Printer.Print ""
Loop
'Print the Page number as a footer
Printer.CurrentX = 8
Printer.CurrentY = FooterTopPosition
Printer.Print "Page: " PageCounter
' 將 輸 出 送 到 打 印 機
Printer.EndDoc
End Sub