Jump to content
Software FX Community

PrintDocument


harsha.k

Recommended Posts

The ChartFX Printer Class provides important and very helpful properties to print the chart. Using the supported members, you will have control over the margins, paper orientation, color or pattern printing, among others. The supported methods will also allow you to prompt the user with page setup, preview, and print dialogs to ensure the user prints exactly what they want; however, this is more of an extended functionality of the PrintDocument Class provided by the .NET Framework. When you print, you still have to create a PrintDocument Object which is handled by the BeginPrint, PrintPage, and EndPrint Events respectively. If you want to manipulate how a page is printed, you will need to do this in the PrintPage Event. Again, this is beyond the scope of ChartFX; however, I will post some code that can help you accomplish what you need. The code snippet is below:

private void Form1_Load(object sender, EventArgs e)

{

printCover = true; // Global flag to control how to print the pages

PrintDocument pd = new PrintDocument();pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

pd.Print();

}

void pd_PrintPage(object sender, PrintPageEventArgs e)

{

if (printCover)

{

e.Graphics.DrawString("This is my cover sheet", new Font("Arial", 14, FontStyle.Bold), Brushes.Black, 25, 25, StringFormat.GenericTypographic);

printCover =

false;

e.HasMorePages =

true; // Forces an additional page to be printed

return

;

}

else

{

chart1.Paint(e.Graphics, new Rectangle(25, 25, e.MarginBounds.Width, e.MarginBounds.Height / 2), PaintStyles.Print);

}

}

The main part of the code is the PrintPage Event which determines how my document is going to be printed. I am using a flag that helps print a first page before printing the chart image. The HasMorePages property, tells the Event Handler that there are more pages to be printed; in this case, we need to print the chart. Hope this helps with what you need.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...