NETTutorial14

From Steema Software Reference Wiki
Jump to: navigation, search

Net.png

Contents page
Previous | Next

Tutorial14 - Printing Charts


Standard Printing

TeeChart Pro offers standard print methods to print the Onscreen Chart 'as is' to the Printer.

Simple Print command

To print a Chart use the Print method. This will print the chart as it appears onscreen:

[C#] 
tChart1.Printer.Print();

[VB.Net]
TChart1.Printer.Print()

Print Orientation

The Print method allows you to print both Landscape and Portrait orientations, even if they are not defined as the default, by the use of the boolean landscape parameter. The default orientation will take effect again after the print is complete. Default Orientation can be changed using the Landscape property (set to true for Landscape, false for Portrait):

[C#] 
tChart1.Printer.Landscape = true;
tChart1.Printer.Print();

[VB.Net]
TChart1.Printer.Landscape = True
TChart1.Printer.Print()

Print Preview

The PrintPreview window will show you how the Chart will appear when printed. You may modify print parameters in the Print Preview window. To call PrintPreview run:

[C#] 
tChart1.Printer.Preview();

[VB.Net]
TChart1.Printer.Preview()

Greyscale printing

When printing to Greyscale printers you should take care that the colours of the Chart are easily distinguishable when translated to shades of grey. To help, you could add Brush styles to the Chart Series to more easily distinguish Series when printed.

You can also print Grayscale Charts to color printers using the Grayscale property:

[C#] 
tChart1.Printer.Grayscale = true;
tChart1.Printer.Print(true);

[VB.Net]
TChart1.Printer.Grayscale = True
TChart1.Printer.Print(True)


Extended Printing methods

Printing multiple Charts

Use BeginPrint() and EndPrint() to send a Chart to the printer without ejecting the page; BeginPrint() and EndPrint() start and end the Printer job. More than one Chart can be sent to the same page/printer job and user custom input can be included too.

Example (Prints 2 Charts to a page): 
[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 previewing several Charts on one page

The Print Previewer now accepts more than one Chart. Chart positions are controlled setting the Rectangle of the Print method.  

Example (Shows 2 Charts in the Print Previewer): 
[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

Mixing printed Chart output with other print output

Use the ChartPrint() event to mix TeeChart print output with non Chart printer output.
The following example takes the text from the TeeChart Headers and prints them on a page with two TChart objects:

[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


[


PREVIOUS

NEXT


© 1998-2019 Steema Software SL. All rights reserved.