Printing in Windows Forms Chart
26 Apr 2021 / 2 minutes to read
The chart provides a PrintDocument that can be sent to the .NET PrintPreviewDialog to get a preview of the chart that gets printed. Here is some code that shows how this is done.
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); //Customizing the icon of print preview dialog (printPreviewDialog1 as Form).Icon = new Icon(@"..\..\App.ico"); printPreviewDialog1.Document = this.chartControl1.PrintDocument; printPreviewDialog1.ShowDialog();
Me.printPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog 'Customizing the icon of print preview dialog CType(printPreviewDialog1,Form).Icon = New Icon("..\..\App.ico") printPreviewDialog1.Document = Me.chartControl1.PrintDocument printPreviewDialog1.ShowDialog()
Print a chart control using the PrintDocument exposed by the chart control as follows:
You can also specify if you want to print the chart in Color or GrayScale using PrintColorMode property.
|Chart control Property||Description|
Indicates the color mode during printing. Possible Values:
this.chartControl1.PrintColorMode = ChartPrintColorMode.GrayScale;
Me.chartControl1.PrintColorMode = ChartPrintColorMode.GrayScale
Automatic GrayScale Handling
Setting GrayScale print mode for the chart lets you print the chart in a gray scale and when multiple series are printed in this case, chart data points are automatically rendered with a patterned brush to differentiate the different series as shown in the image below.
A sample illustrating the printing features is available in the below location.
<Install Location>\Syncfusion\EssentialStudio<Install version>\Windows\Chart.Windows\Samples\Print\Chart Print
Displaying ToolBar while printing
chartControl1.ShowToolbar = true; chartControl1.PrintDocument.PrintToolBar = true;
chartControl1.ShowToolbar = True chartControl1.PrintDocument.PrintToolBar = True