使用C#Windows应用程序打印表单
问题描述:
海专家
我想打印一个用户填写的实验室帐单"表格,而无需创建报告.我是Windows Apps的新手,(大多熟悉Asp.net).
我的代码如下所示
1)在一个按钮中单击此代码
Hai Experts
I want to print a ''Lab bill" Form that the user has filled out without having to create a report. I am new to Windows Apps, (mostly famliar with Asp.net).
My code is given bellow
1) this code in a button click
ControlPrint mp = new ControlPrint(panel1);
mp.PrintWidth = mp.CalculateSize().Width;
mp.PrintHeight = mp.CalculateSize().Height;
PrintDialog PrintDialog1 = new PrintDialog();
System.Drawing.Printing.PrintDocument docToPrint =
new System.Drawing.Printing.PrintDocument();
PrintDialog1.AllowSomePages = true;
PrintDialog1.ShowHelp = true;
PrintDialog1.Document = docToPrint;
DialogResult result = PrintDialog1.ShowDialog();
if (result == DialogResult.OK)
{
docToPrint.Print();
}
2)
2)
public void StartPrint(Stream streamToPrint, string streamType)
{
this.printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
this.streamToPrint = streamToPrint;
this.streamType = streamType;
System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();
PrintDialog1.AllowSomePages = true;
PrintDialog1.ShowHelp = true;
PrintDialog1.Document = printDocument1;
DialogResult result = PrintDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}
}
但是我尝试了这个示例,并且只从打印机中取出空白页
我的代码有什么问题,请帮帮我
我提前致谢
but I tried this example and only get a blank page out of the printer
what is the problem in my code and please help me
i give a thanks in advance
答
一个非常简单的解决方案:http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/eb80fbbe-6b89-4c3d-9ede-88a2b105c714 [ ^ ]
还要检查以下内容:
-不使用API打印Windows窗体 [ http://msdn.microsoft.com/en-us/library/aa287529(v = vs.71).aspx [
One quite simple solution: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/eb80fbbe-6b89-4c3d-9ede-88a2b105c714[^]
Also check these:
- Print Windows Forms w/o using API[^]
- http://msdn.microsoft.com/en-us/library/aa287529(v=vs.71).aspx[^]
您可以使用
可视化基本Powerpack的printform组件来打印表单.
或
您可以使用打印文档类
You can use
visual basic powerpacks printform component to print a form.
or
you can use printdocument class
此处 [ ^ ]是一些建议和文章.
Here[^] are some suggestions and articles.