Printing a Chart
Printing Basics
Printing of a chart is accomplished via the PrintingManager class, which is exposed as the Printing property of the root Chart object. This PrintManager class belongs to the Dundas.Charting.WinControl.Utilities namespace.
When a chart is printed all chart elements, except for scrollbars, will be printed.
To print only part of a chart first create a view, then print the chart and then reset the chart to its previous view state. For further information on data views see the Scrolling and Zooming topic for further details.
To access a .NET PrintDocument object use the PrintDocument property (described in the next section of this article). The PrintDocument class is a reusable object that allows for the setting of printing properties (e.g. margins) and then sends output to a printer.
To embed a chart inside a custom paint routine use the PrintPaint method (described in detail in the Custom Drawing Routines section).
Using the PrintDocument Object
The .NET PrintDocument class is a reusable object that can be used to set printing-related properties and then send output to a printer, and is exposed via the PrintDocument property. Use this object when you need to perform a printing-related task that isn't possible using the utility methods of the chart's PrintingManager object.
Example
In the following sample we set the margins to 0.5 inches, and then print the chart without displaying the Print Dialog. Note that margins are measured in 1/100 of an inch.
Visual Basic | ![]() |
---|---|
|
C# | ![]() |
---|---|
|
Custom Drawing Routines and the PrintPaint method
Custom printing routines are implemented using the PrintPage event of a PrintDocument object, and the PrintPaint method of the chart's PrintingManager class is designed to facilitate embedding a chart in this event.
The PrintPaint method prints a chart at the page location that is set by the Position parameter value, which is of type Rectangle.
When using this method the Graphics object used for the g parameter MUST be the Graphics object of the PrintPageEventArgs parameter (see sample source code below).
Example
The following example prints a line of text, the chart and then another line of text using a custom drawing routine via the PrintPage event of a PrintDocument object. Note that we use the Graphics object from the PrintPageEventArgs parameter as the Graphics parameter for the PrintPaint method call.
Visual Basic | ![]() |
---|---|
|
C# | ![]() |
---|---|
|