如何在Windows应用程序中打印Web表单 [英] how to print a web form in windows application

查看:71
本文介绍了如何在Windows应用程序中打印Web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击打印按钮时,我想打印一个表格,因为我正在使用printform组件,但它显示我选择一个文件,就像我们上传的东西一样。



我该怎么做

I wanna a form to print when i click on print button,for that I'm using printform component but it showing me a to select a file like when we upload something.

how can i do this

推荐答案

private void ButtonPrintClick(object sender,EventArgs e)

{

//创建文档

PrintDocument _document = new PrintDocument();

//添加打印处理程序

_document.PrintPage + = new PrintPageEventHandler(Document_PrintPage);

//创建显示结果的对话框

PrintPreviewDialog _dlg = new PrintPreviewDialog();

_dlg.ClientSize = new System.Drawing.Size(Width / 2,Height / 2);

_dlg.Location = new System.Drawing.Point(Left,Top);

_dlg。 MinimumSize = new System.Drawing.Size(375,250);

_dlg.UseAntiAlias = true;

//设置我们的文件

_dlg.Document = _document;

//显示它

_dlg.ShowDialog(this);

//处理文件

_document.Dispose();

}

//打印处理程序

private void Document_PrintPage(object sender,PrintPageEventArgs e)

{

//创建位图表单大小

位图_bitmap =新位图(宽度,高度,System.Drawing.Imaging.PixelFormat.Format32bppRgb);

//从位图DC绘制

this.DrawToBitmap(_bitmap,this.DisplayRectangle);

//将位图绘制到打印机DC

e.Graphics.DrawImage(_bitmap,0,0) ;

//不再需要 - 处理它

_bitmap.Dispose();

}



试试这个并告诉我
private void ButtonPrintClick(object sender, EventArgs e)
{
// Create document
PrintDocument _document = new PrintDocument();
// Add print handler
_document.PrintPage += new PrintPageEventHandler(Document_PrintPage);
// Create the dialog to display results
PrintPreviewDialog _dlg = new PrintPreviewDialog();
_dlg.ClientSize = new System.Drawing.Size(Width / 2, Height / 2);
_dlg.Location = new System.Drawing.Point(Left, Top);
_dlg.MinimumSize = new System.Drawing.Size(375, 250);
_dlg.UseAntiAlias = true;
// Setting up our document
_dlg.Document = _document;
// Show it
_dlg.ShowDialog(this);
// Dispose document
_document.Dispose();
}
// Print handler
private void Document_PrintPage(object sender, PrintPageEventArgs e)
{
// Create Bitmap according form size
Bitmap _bitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
// Draw from into Bitmap DC
this.DrawToBitmap(_bitmap, this.DisplayRectangle);
// Draw Bitmap into Printer DC
e.Graphics.DrawImage(_bitmap,0,0);
// No longer deeded - dispose it
_bitmap.Dispose();
}

Try this and let me know


这篇关于如何在Windows应用程序中打印Web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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