如何打印字符串 [英] How to print a String
本文介绍了如何打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何打印出我的WinForms生成的字符串?我想打印出字符串坐落在一个用户控件。
这是我已经有了。当我按下打印按钮,没有任何被打印出来。
私人无效print_Click(对象发件人,EventArgs五)
{
PrintDialog类PrintDialog类=新PrintDialog类();
的PrintDocument PrintDocument的=新的PrintDocument();
printDialog.Document =的PrintDocument;
printDocument.PrintPage + =新PrintPageEventHandler(printDocument_PrintPage);
DialogResult的结果= printDialog.ShowDialog();
如果(结果== DialogResult.OK)
{
printDocument.Print();
}
的PrintDocument recordDoc;
//创建该文件并将其命名为
recordDoc =新的PrintDocument();
recordDoc.DocumentName =客户回执;
recordDoc.PrintPage + =新PrintPageEventHandler(this.PrintReceiptPage);
//预览文件
dlgPreview.Document = recordDoc;
dlgPreview.ShowDialog();完成打印
recordDoc.Dispose当
//处置文件();
}
解决方案
在PrintPage事件试试这个
e1.Graphics.DrawString(S,新的字体(宋体,12),新SolidBrush(Color.Black ),新的RectangleF(0,0,p.DefaultPageSettings.PrintableArea.Width,p.DefaultPageSettings.PrintableArea.Height));
试
{
p.Print();
}
赶上(异常前)
{
抛出新的异常(异常发生时打印,前);
}
How do I print out a String that I generated in Winforms? The String I'd like to print out is located in a UserControl.
This is what I already have. When I press the Printing Button, nothing is printed.
private void print_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
printDialog.Document = printDocument;
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
DialogResult result = printDialog.ShowDialog();
if (result == DialogResult.OK)
{
printDocument.Print();
}
PrintDocument recordDoc;
// Create the document and name it
recordDoc= new PrintDocument();
recordDoc.DocumentName = "Customer Receipt";
recordDoc.PrintPage += new PrintPageEventHandler(this.PrintReceiptPage);
// Preview document
dlgPreview.Document = recordDoc;
dlgPreview.ShowDialog();
// Dispose of document when done printing
recordDoc.Dispose();
}
解决方案
In the PrintPage event try this
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
try
{
p.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
这篇关于如何打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文