Hi Lee,
Generally when you use custom printing you should not rely on the chart print manager - instead you need to create your own print document and print the charts there one by one. The following code snippet shows how to achieve this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// init the first chart
{
NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
chart.BoundsMode = BoundsMode.Stretch;
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);
}
// init the second chart
{
NCartesianChart chart = (NCartesianChart)nChartControl2.Charts[0];
chart.BoundsMode = BoundsMode.Stretch;
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);
}
}
private PrintDocument CreatePrintDocument()
{
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += new PrintPageEventHandler(OnPrintPage);
return printDocument;
}
private void OnPrintPage(object sender, PrintPageEventArgs ev)
{
RectangleF marginBounds = new RectangleF(ev.MarginBounds.Left, ev.MarginBounds.Top, ev.MarginBounds.Width, ev.MarginBounds.Height);
// create header and footer
string header = "Custom Header";
string footer = "Custom Footer";
Font font = new Font("Arial", 15);
Brush brush = new SolidBrush(Color.Black);
// measure them
SizeF headerSize = ev.Graphics.MeasureString(header, font);
SizeF footerSize = ev.Graphics.MeasureString(footer, font);
// draw header
RectangleF headerBounds = new RectangleF(marginBounds.Left, marginBounds.Top, marginBounds.Width, headerSize.Height);
ev.Graphics.DrawString(header, font, brush, headerBounds);
float chartSize = (marginBounds.Height - headerSize.Height - footerSize.Height) / 2;
// draw chart
NRectangleF firstChartBounds = new NRectangleF(marginBounds.Left, headerBounds.Bottom, marginBounds.Width, chartSize);
using (NChartPrintView printView = new NChartPrintView(nChartControl1.PrintManager, nChartControl1.Document, ev.Graphics))
{
printView.Print(firstChartBounds);
}
NRectangleF secondChartBounds = new NRectangleF(marginBounds.Left, headerBounds.Bottom + chartSize, marginBounds.Width, chartSize);
using (NChartPrintView printView = new NChartPrintView(nChartControl2.PrintManager, nChartControl1.Document, ev.Graphics))
{
printView.Print(secondChartBounds);
}
// draw footer
RectangleF footerBounds = new RectangleF(marginBounds.Left, marginBounds.Bottom - footerSize.Height, marginBounds.Width, footerSize.Height);
ev.Graphics.DrawString(footer, font, brush, footerBounds);
// dispose objects
font.Dispose();
brush.Dispose();
}
private void ShowPrintPreviewButton_Click(object sender, EventArgs e)
{
try
{
PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
printPreviewDialog.Document = CreatePrintDocument();
printPreviewDialog.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
This will create e print page with two charts, header and footer. Let us know if you meet any problems or have any questions...
Best Regards,
Nevron Support Team