代码之家  ›  专栏  ›  技术社区  ›  Alex Gordon

c#ms图表-打印图表的最佳方式是什么?

  •  0
  • Alex Gordon  · 技术社区  · 14 年前

    我在窗体上有一个ms图表控件,我想打印该图表。最好的方法是什么?

    2 回复  |  直到 14 年前
        1
  •  1
  •   Steven    14 年前

    对于您的目的,这可能有点复杂,但是我使用了 PrintDocument 对象在报表页上绘制背景图像。您可以执行类似的操作,使用PrintPageEventArgs中的Graphics对象来“绘制”图表图像。

    此代码将打印一个1页的文档,并在上角绘制一个小矩形。我想你可以把那里的画换成你的图表

    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();
    }
    
    }
    
        2
  •  1
  •   M. Cota    12 年前

    另一个灵活的解决方案是将图表导出到PDF,并让用户从Adobe Reader打印出来,他/她将能够保存图表或通过电子邮件发送它…