以下示例一次從文件中讀取一行,然后將每行文本打印到控制臺。
創(chuàng)新互聯(lián)是一家專業(yè)提供老城企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都網(wǎng)站設(shè)計、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為老城眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。
Sub ReadTextLinesFromFile()
Dim file As New System.IO.StreamReader("c:test.txt")
Dim oneLine As String
oneLine = file.ReadLine()
While (oneLine "")
Console.WriteLine(oneLine)
oneLine = file.ReadLine()
End While
file.Close()
End Sub
報表打印應(yīng)該也能實現(xiàn),但是我覺得你這個用文本打印更簡單,將數(shù)據(jù)輸出到txt文件,結(jié)果用RichTextBox顯示,但是需要簡單的排版,調(diào)用打印機(jī)打印RichTextBox即可的
排版用tab()、space()、vbcrlf或PrintLine(1)換行,代碼類似如下樣式
PrintLine(1, TAB(60), "準(zhǔn)考證" )
PrintLine(1)
PrintLine(1, "姓名:" xingming Space(3) "準(zhǔn)考證號:" cel(1) Space(3) cel(2) Space(3) cel(3))
但是TAB()排版比較規(guī)整
打印代碼類似如下:
PrintDialog1.Document = PrintDocument1
PrintDocument1.DocumentName = "準(zhǔn)考證"
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 '頁面設(shè)置
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
If PrintDialog1.PrinterSettings.IsValid = True Then
PrintDocument1.Print()
MsgBox("打印完成!" vbCrLf "Print completed!", , "Print hint(打印提示)")
Else
MsgBox("打印失??!打印機(jī)不可用。" vbCrLf "Print failed! The printer is not valid.", , "Print hint(打印提示)")
End If
Else
Exit Sub
End If
End If
一行數(shù)據(jù)分三次打印 那你一行數(shù)據(jù)里面有沒有特殊符號 還是只需要一行分三次打印出來
比如:
Private Sub Document_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.DrawString(str0, New Font("Arial", 14, FontStyle.Regular), Brushes.Black, 50, 50)
e.Graphics.DrawString(A1, New Font("Arial", 10, FontStyle.Regular), Brushes.Black,50, 100)
e.Graphics.DrawString(A2, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 300,100)
e.Graphics.DrawString(A3, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 800,100)
也就是分次用不同坐標(biāo)和不同的字體來打印各變量。畫線用:
e.Graphics.DrawLine(BlackPen, x1, y1, x2, y2)。
具體坐標(biāo)數(shù)值自己用尺量出,再換算。