简体   繁体   English

当我打印位图时,它会吃掉一些

[英]When I print bitmap, it eats up some of it

In my application i have a chart which is surrounded inside a panel. 在我的应用程序中,我有一个图表,它被包围在一个面板内。 I added a printdocument component from the toolbox and when i want to print the chart, i am creating a bitmap and i get the panel inside the bitmap (and as a result the chart which is inside the panel). 我从工具箱中添加了一个printdocument组件,当我想打印图表时,我正在创建一个位图,我将面板放在位图内(结果是面板内的图表)。 My problem is that when i create the bitmap, when i send it to the printer to print it, it eats up some of the chart from the bottom and from the right side. 我的问题是,当我创建位图时,当我将它发送到打印机进行打印时,它会从底部和右侧吃掉一些图表。 Below is my code to execute this 下面是我执行此操作的代码

private void button1_Click(object sender, EventArgs e)
    {
        PrintDialog printDialog = new PrintDialog();
        printDialog.Document = printDocument1;
        printDialog.UseEXDialog = true;
        //Get the document

        if (DialogResult.OK == printDialog.ShowDialog())
        {
            printDocument1.DocumentName = "Test Page Print";
            printPreviewDialog1.Document = printDocument1;

            if (DialogResult.OK == printPreviewDialog1.ShowDialog())
            printDocument1.Print();
        }
    }

This is the button to initialize the print_document. 这是初始化print_document的按钮。 (I added a print preview so that i don't have to print it every time and spent paper and ink) (我添加了一个打印预览,这样我就不必每次都打印它并用纸和墨水)

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        Bitmap bm = new Bitmap(this.panel1.Width, this.panel1.Height);
        this.panel1.DrawToBitmap(bm, new Rectangle(50, 50, this.panel1.Width + 50, this.panel1.Height + 50));
        e.Graphics.DrawImage(bm, 0, 0);
    }

I was thinking that maybe the chart is too big and it doesn't fit in the page but if i save the bitmap. 我在想,也许图表太大了,它不适合页面,但如果我保存位图。 it fits OK inside the page actually there is too much free space on the bottom and right side. 实际上在底部和右侧有太多的自由空间。 (After the draw to bitmap function add (绘制到位图功能后添加

bm.Save(@"c:\LOAN_GRAPH.png");

instead of the draw image and the image is save in c:) 而不是绘制图像,图像保存在c :)

Anybody who can help me i would be truly thankful. 任何可以帮助我的人都会非常感激。

Its working. 它的工作。 I removed the panel and instead, i am creating the rectangle according to my chart. 我删除了面板,而是根据我的图表创建矩形。

Bitmap bm = new Bitmap(this.chart1.Width, this.chart1.Height);
    this.chart1.DrawToBitmap(bm, new Rectangle(50, 50, this.chart1.Width + 50, this.chart1.Height + 50));
    e.Graphics.DrawImage(bm, 0, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM