Alex Gordon
Alex Gordon

Reputation: 60912

c# ms chart - what is the best way to print a chart?

i have an ms chart control on the form and i would like to print the chart. what is the best way to do this?

Upvotes: 0

Views: 2878

Answers (2)

M. Cota
M. Cota

Reputation: 15

Another flexible solution is to export the chart to PDF and let the user print it out from Adobe Reader, and he/she will be able to save the chart or send it by email as well...

Upvotes: 1

Steven
Steven

Reputation: 1280

This might be a bit convoluted for your purposes, but I've used the PrintDocument object to draw a background image on pages of a report. You could do something similar, where you use the Graphics object from the PrintPageEventArgs to "paint" your chart image.

This code would print a 1 page document with a small rectangle drawn in the upper corner. I would think you could replace the drawing there with the drawing of your chart

class Program
{
public class Document : System.Drawing.Printing.PrintDocument
{
    protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
    {
        base.OnBeginPrint(e);
    }
    protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawRectangle(SystemPens.ActiveBorder, new Rectangle(0, 0, 20, 20));
    }
}

static void Main(string[] args)
{
    System.Drawing.Printing.PrintDocument pd = new Document();
    pd.Print();
}

}

Upvotes: 1

Related Questions