Winforms在C#中打印面板的所有内容 [英] winforms printing all the contents of a panel in C#

查看:74
本文介绍了Winforms在C#中打印面板的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用于从面板打印的代码

I have the following code for printing from a panel

public void PrepareImage()
 Graphics graphic = panel2.CreateGraphics();
            Size s = panel2.Size;
            memImage = new Bitmap(s.Width, s.Height, graphic);
            Graphics memGraphic = Graphics.FromImage(memImage);
            IntPtr dc1 = graphic.GetHdc();
            IntPtr dc2 = memGraphic.GetHdc();
            BitBlt(dc2, 0, 0, panel2.ClientRectangle.Width,
            panel2.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
            graphic.ReleaseHdc(dc1);
            memGraphic.ReleaseHdc(dc2);   
        }    
        private void btnprint_Click(object sender, EventArgs e)
        {
            PrepareImage();
            printDocument1.Print();
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap bmp=new Bitmap(panel2.Width, panel2.Height);
            panel2.DrawToBitmap(bmp, new Rectangle(0, 0, panel2.Width, panel2.Height));
            e.Graphics.DrawImage(bmp, 0, 0);
}



但是它不会打印整个面板(整个宽度都不会出现).
实际上,面板超出了表单的宽度.我希望调整内容的大小以适合一页.



But it does n''t print the entire panel (entire width is not coming).
Actually the panel exceeds the width of the form . I want the contents to be resized to fit in one page.

推荐答案

尝试此链接:thumbsup:
如何打印零件 [
try this link :thumbsup:
How to print part of the window form in c# window application?[^]


最好的选择是忘记创建图像小组并集中精力根据小组内包含的信息创建适当的文档.您可以使用GDI + API来执行此操作. 此处 [
Your best bet would be to forget about creating an image of the panels and concentrate on creating a proper document from the information that is contained within the Panels. You can do this with the GDI+ API. Here[^] is the MSDN Article on that topic.

Hope this helps


这篇关于Winforms在C#中打印面板的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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