开发者

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

i have an ms chart control on the form and i wou开发者_JAVA百科ld like to print the chart. what is the best way to do this?


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();
}

}


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜