如何使用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();