English 中文(简体)
当我打印比特图时,它会吃掉一部分
原标题:When I print bitmap, it eats up some of it

在应用程序中,我有一个图表,它环绕在一个面板内。我从工具框中添加了一个打印文档组件,当我想打印图表时,我正在创建一个位图,然后我把面板放到位图(并因此在面板内的图表)中。我的问题是,当我创建位图时,当我把它发送到打印机打印时,它会从底部和右侧吃掉一些图表。下面是我用来执行的代码。

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

这是初始化打印文件的按钮 。 (我添加了打印预览, 这样我不必每次打印, 以及用过的纸张和墨水)

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

我在想,也许图表太大,不适合页面,但如果我保存了位图。它符合页面内部的正常要求。实际上,底侧和右侧有太多空闲空间。 (在绘制位图函数后添加了位图函数)

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

而不是绘图图像,图像保存在 c:)

任何能帮我的人 我会非常感激的

最佳回答

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);
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签