如何打印字符串
本文关键字:字符串 打印 何打印 | 更新日期: 2023-09-27 18:07:29
如何打印出我在Winforms中生成的字符串?我想打印出来的字符串位于UserControl中。
这是我已经有的。当我按下打印按钮时,没有打印任何东西。
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();
}
在PrintPage事件中试试这个
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);
}
取自https://social.msdn.microsoft.com/Forums/en-US/93e54c4f-fd07-4b60-9922-102439292f52/c-printing-a-string-to-printer?forum=csharplanguage