利用 printdocument控件
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、虛擬主機(jī)、營(yíng)銷軟件、網(wǎng)站建設(shè)、寧陜網(wǎng)站維護(hù)、網(wǎng)站推廣。
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" '打印的內(nèi)容
e.Graphics.DrawString(s, stringFont, Brushes.AliceBlue, rectDraw, strFormat)
End Sub
先拖過(guò)來(lái)控件PrintDocument1,然后雙擊PrintDocument1,在它的PrintPage事件中加入代碼如下:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
dim a as String
a="abcd"
Dim mypen As Pen = New Pen(Color.Blue, 2)
e.Graphics.DrawString(a, New Font("宋體", 20), New Pen(Color.Black, 1).Brush, 30, 30)
End Sub
調(diào)用下面語(yǔ)句可直接用默認(rèn)打印機(jī)打印出來(lái):
PrintDocument1.Print()
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來(lái)打印了,