如何使用C#在A4纸上打印表格? [英] How to print a form in an A4 sheet using c#?

查看:508
本文介绍了如何使用C#在A4纸上打印表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何在A4表格中使用标题栏和控件打印表单.我尝试了很多代码,但无法获得结果.请告诉代码.

谢谢

Hi,

How to print a form with it''s title bar and controls in an A4 sheet.I have tried many codes but couldn''t get the result.Kindly tell the code.

Thank you

推荐答案

从工具箱中添加printDocument和printDialog控件.

然后

Add printDocument and printDialog control from toolbox.

then

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap img = new Bitmap(this.Width, this.Height);
//define which is to print
            this.DrawToBitmap(img,new Rectangle(0,0,this.Width,this.Height));
            Graphics g=e.Graphics;
            g.PageUnit=GraphicsUnit.Display;
            g.DrawImage(img,new RectangleF(0,0,this.Width,this.Height));

    }



并添加打印按钮button1->



and Add a print button button1 -->

private void button1_Click(object sender, EventArgs e)
        {
            printDocument1.Print();

        }


在Visual Studio中使用Visual Basic Power Pack的printForm控件.
此控件在Visual Studio的工具箱中可用.

转到Visual Studio的工具箱
> Visual Basic电源包
>将PrintForm组件拖动到表单
>在按钮单击事件上编写代码
use printForm control of Visual Basic power packs in visual studio.
this control available in Toolbox of visual studio.

Go to ToolBox of visual Studio
>Visual Basic Power Packs
>Drag PrintForm component to the form
>On button click event write the code
this.printForm1.Print();


这篇关于如何使用C#在A4纸上打印表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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