在打印前调整MSChart的大小以适合页面大小 [英] Resize MSChart to Fit Pagesize Before Printing

查看:81
本文介绍了在打印前调整MSChart的大小以适合页面大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力弄清楚如何在打印时获取MSChart来填充整个页面。有人可以告诉我为什么下面的代码不起作用和/或建议另一种方法。我为我的无知表示歉意,但是到目前为止,我所做的所有打印工作都是通过Crystal和其他报表框架完成的,因此,我通常不必直接使用PrintDialog和PrintPreviewDialog。

I am struggling to figure out how to get an MSChart to fill the entire page when printing. Can someone tell me why the code below does not work and/or suggest another approach. I apologize for my ignorance but, all of the printing I have done so far has been done through Crystal and other reporting frameworks so I generally never have to work directly with the PrintDialog and PrintPreviewDialog. Thanks in advance.

// Printing Code
Size pageSize = new Size(this.Chart.Printing.PrintDocument.DefaultPageSettings.PaperSize.Width, this.Chart.Printing.PrintDocument.DefaultPageSettings.PaperSize.Height);
this.Chart.Size = pageSize;

// This properly previews my chart but, it does not fill up the page                    
this.Chart.Printing.PrintPreview();


推荐答案

好的,所以我终于弄清楚了如何完成任务我正在尝试做。归结为我不了解如何将PrintDocument与Graphics对象一起使用。我用来完成任务的代码如下。我真的希望这对某人有帮助。另外,我强烈推荐MSFT图表样本代码。当我创建这些图表时,它对我来说是无价的。链接为: http://archive.msdn.microsoft.com /mschart/Release/ProjectReleases.aspx?ReleaseId=4418

Okay, so I finally figured out how to accomplish what I was trying to do. It boiled down to me not understanding how to use a PrintDocument with the Graphics object. The code that I used to accomplish the task is below. I really hope this helps someone. Also, I highly recommend the MSFT Chart Sample Code. It has proven to be invaluable to me as I create these charts. The link is: http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418

    public void PrintPreviewIncompleteJobsByStatus()
    {
        // Set new print document with custom page printing event handler
        chart.Printing.PrintDocument = new PrintDocument();
        chart.Printing.PrintDocument.PrintPage += new PrintPageEventHandler(ChartGenericFormat_PrintPage);

        chart.Printing.PrintDocument.DefaultPageSettings.Landscape = true;

        // Print preview chart
        chart.Printing.PrintPreview();
    }

    private void ChartGenericFormat_PrintPage(object sender, PrintPageEventArgs ev)
    {
        // Calculate first chart position rectangle
        Rectangle chartPosition = new Rectangle(ev.MarginBounds.X, ev.MarginBounds.Y, ev.MarginBounds.Width, ev.MarginBounds.Height);

        // Draw chart on the printer graphics
        chart.Printing.PrintPaint(ev.Graphics, chartPosition);

    }

这篇关于在打印前调整MSChart的大小以适合页面大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆