private void printReceipt()
{
printDialog.Document = printDocument;
DialogResult result = printDialog.ShowDialog();
if (result != DialogResult.OK) return;
try
{
sPrint = new StreamReader(
new MemoryStream(
Encoding.ASCII.GetBytes(richTextBoxResult.Text)));
printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
printDocument.Print();
}
catch (Exception e)
{
MessageBox.Show("Failed to print \n" + e.Message);
}
finally
{
if (sPrint != null)
sPrint.Close();
}
}
void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
// No of lines that fit on to the page
float linesPerPage = e.MarginBounds.Height / richTextBoxResult.Font.GetHeight(e.Graphics);
float fontHeight = richTextBoxResult.Font.GetHeight(e.Graphics);
for (int count = 0; count < linesPerPage && !sPrint.EndOfStream; count++)
{
e.Graphics.DrawString(sPrint.ReadLine(),
richTextBoxResult.Font,
Brushes.Black,
e.MarginBounds.Left,
e.MarginBounds.Top + (count * fontHeight),
new StringFormat());
}
e.HasMorePages = !sPrint.EndOfStream;
}
我的问题:-
- 打印时,我需要正确调整所有文本框内容。(冗长的单行没有打印,而是跳出页面)
- 是否有可能在打印菜单下启用打印范围选项?(在输出 GUI 上,假设我有可以放在多个页面上的文本内容)
请帮忙。谢谢你。