1. 程式人生 > >【TeeChart Pro ActiveX教程】(十四):列印圖表

【TeeChart Pro ActiveX教程】(十四):列印圖表

下載TeeChart Pro ActiveX最新版本

標準列印

TeeChart Pro提供標準列印方法,可將“螢幕圖表”按原樣列印到印表機。

簡單列印命令

要列印圖表,請使用Print方法。這將打印出螢幕上顯示的圖表:

[C#]

tChart1.Printer.Print();

[VB.Net]

TChart1.Printer.Print()

列印方向

Print方法允許您通過使用布林橫向引數來列印橫向和縱向方向,即使它們未被定義為預設方向。列印完成後,預設方向將再次生效。可以使用Landscape屬性更改預設方向(對於Landscape,設定為true,對於Portrait,設定為false):

[C#]

tChart1.Printer.Landscape = true; 
tChart1.Printer.Print();

[VB.Net]

TChart1.Printer.Landscape = True 
TChart1.Printer.Print()

列印預覽

PrintPreview視窗將顯示列印時圖表的顯示方式。您可以在“列印預覽”視窗中修改列印引數。要呼叫PrintPreview執行:

[C#]

tChart1.Printer.Preview();

[VB.Net]

TChart1.Printer.Preview()

灰度列印

當列印到Greyscale印表機時,您應該注意圖表的顏色在轉換為灰色陰影時很容易區分。為了提供幫助,您可以在圖表系列中新增畫筆樣式,以便在列印時更輕鬆地區分系列。

您還可以使用灰度屬性將彩×××表列印到彩色印表機:

[C#]

tChart1.Printer.Grayscale = true; 
tChart1.Printer.Print(true);

[VB.Net]

TChart1.Printer.Grayscale = True 
TChart1.Printer.Print(True)

擴充套件列印方法

列印多個圖表

使用BeginPrint()和EndPrint()將圖表傳送到印表機而不彈出頁面; BeginPrint()和EndPrint()開始和結束印表機作業。可以將多個圖表傳送到同一頁面/印表機作業,也可以包含使用者自定義輸入。

(將2個圖表列印到頁面)

[C#]

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

在一個頁面上列印預覽多個圖表

列印預覽器現在可以接受多個圖表。控制圖表位置設定Print方法的Rectangle。

(在列印預覽器中顯示2個圖表)

[C#]

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

將列印的圖表輸出與其他列印輸出混合

使用ChartPrint()事件將TeeChart列印輸出與非Chart印表機輸出混合。 以下示例從TeeChart標題中獲取文字,並在具有兩個TChart物件的頁面上列印它們:

[C#]

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