【TeeChart .NET教程】(十四)打印圖表
【下載TeeChart.Net最新版本】
(一)標(biāo)準(zhǔn)打印
TeeChart Pro提供標(biāo)準(zhǔn)打印方法,可將“Onscreen Chart屏幕圖表”按原樣打印到打印機(jī)。
1.1 簡(jiǎn)單打印命令
要打印圖表,請(qǐng)使用Print方法。這將打印出屏幕上顯示的圖表:
[C#.Net]
tChart1.Printer.Print();
[VB.Net]
TChart1.Printer.Print()
1.2 打印方向
Print方法允許您使用布爾橫向參數(shù)打印橫向和縱向方向,即使它們未定義為默認(rèn)方向。打印完成后,默認(rèn)方向?qū)⒃俅紊?。可以使用Landscape屬性更改默認(rèn)方向(對(duì)于Landscape,設(shè)置為true,對(duì)于Portrait,設(shè)置為false):
[C#.Net]
tChart1.Printer.Landscape = true; tChart1.Printer.Print();
[VB.Net]
TChart1.Printer.Landscape = True TChart1.Printer.Print()
1.3 打印預(yù)覽
PrintPreview窗口將顯示打印時(shí)圖表的顯示方式,在“Print Preview window打印預(yù)覽”窗口中修改打印參數(shù),要調(diào)用PrintPreview運(yùn)行:
[C#.Net]
tChart1.Printer.Preview();
[VB.Net]
TChart1.Printer.Preview()
1.4 灰度打印
當(dāng)打印到Greyscale打印機(jī)時(shí),圖表的顏色在轉(zhuǎn)換為灰色陰影時(shí)很容易區(qū)分,為了提供幫助,可以在圖表系列中添加畫筆樣式,以便在打印時(shí)更輕松地區(qū)分系列,還可以使用灰度屬性將彩色圖表打印到彩色打印機(jī):
[C#.Net]
tChart1.Printer.Grayscale = true; tChart1.Printer.Print(true);
[VB.Net]
TChart1.Printer.Grayscale = True TChart1.Printer.Print(True)
(二)擴(kuò)展打印方法
2.1 打印多個(gè)圖表
使用BeginPrint()和EndPrint()將圖表發(fā)送到打印機(jī)而不彈出頁面; BeginPrint()和EndPrint()開始和結(jié)束打印機(jī)作業(yè)。可以將多個(gè)圖表發(fā)送到同一頁面/打印機(jī)作業(yè),也可以包含用戶自定義輸入,例:
[C#.Net]
private void button1_Click(object sender, System.EventArgs e) { tChart1.Printer.BeginPrint(); tChart1.Printer.Print(tChart2.Chart,new Rectangle(100,10,300,200)); tChart1.Printer.Print(new Rectangle(100,300,300,200)); tChart1.Printer.EndPrint(); }
[VB.Net]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TChart1.Printer.BeginPrint() TChart1.Printer.Print(TChart2.Chart, New Rectangle(100, 10, 300, 200)) TChart1.Printer.Print(New Rectangle(100, 300, 300, 200)) TChart1.Printer.EndPrint() End Sub
2.2 在一個(gè)頁面上打印預(yù)覽多個(gè)圖表
打印預(yù)覽器現(xiàn)在可以接受多個(gè)圖表,控制圖表位置設(shè)置Print方法的Rectangle,例:
[C#.Net]
private void button1_Click(object sender, System.EventArgs e) { tChart1.Printer.BeginPrint(); tChart1.Printer.Print(tChart2.Chart,new Rectangle(100,10,300,200)); tChart1.Printer.Print(new Rectangle(100,300,300,200)); tChart1.Printer.Preview(); }
[VB.Net]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TChart1.Printer.BeginPrint() TChart1.Printer.Print(TChart2.Chart, New Rectangle(100, 10, 300, 200)) TChart1.Printer.Print(New Rectangle(100, 300, 300, 200)) TChart1.Printer.Preview() End Sub
2.3 將打印的圖表輸出與其他打印輸出混合
使用ChartPrint()事件將TeeChart打印輸出與非Chart打印機(jī)輸出混合,以下示例從TeeChart標(biāo)題中獲取文本,并在具有兩個(gè)TChart對(duì)象的頁面上打印它們:
[C#.Net]
private void button1_Click(object sender, System.EventArgs e) { tChart1.Printer.BeginPrint(); tChart1.Printer.Print(tChart2.Chart,new Rectangle(100,10,300,200)); tChart1.Printer.Print(new Rectangle(100,300,300,200)); tChart1.Printer.EndPrint(); } private void tChart1_ChartPrint(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawString("Chart: "+((Steema.TeeChart.ChartPrintJob)sender).Chart.Header.Text, this.Font,new SolidBrush(Color.Black),100,((Steema.TeeChart.ChartPrintJob)sender).ChartRect.Bottom+10); }
[VB.Net]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TChart1.Printer.BeginPrint() TChart1.Printer.Print(TChart2.Chart, New Rectangle(100, 10, 300, 200)) TChart1.Printer.Print(New Rectangle(100, 300, 300, 200)) TChart1.Printer.EndPrint() End Sub Private Sub TChart1_ChartPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles TChart1.ChartPrint e.Graphics.DrawString("Chart: " & (CType(sender, Steema.TeeChart.ChartPrintJob)).Chart.Header.Text, _ Me.Font, New SolidBrush(Color.Black), 100, (CType(sender, Steema.TeeChart.ChartPrintJob)).ChartRect.Bottom + 10) End Sub