本文介绍了代码生成的打印纸在纸上变成空白!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我一直在试图弄清楚为什么我的程序只打印空白页!
我将VS2010与C#WPF一起使用.该程序本身不会崩溃或引发任何错误,但会经历打印文本框中内容的动作.
我真的不知道我在这里想念的是什么,我看过一些书籍,网络等示例,但无济于事!
如果有任何建议,我将表示欢迎.
这是代码的印刷部分:
Hi all,
I''ve been trying to figure out why my program only prints blank pages!
I use VS2010 with C# WPF. The program itself does not crash or throw any error, but it goes through the motions of printing what''s in the textBox.
I don''t really know what I''m missing here, I''ve looked at some examples in books, web, etc... but no avail!
I would welcome any suggestions if any.
Here''s the printing part of the code:
private void printNumberList(object sender, RoutedEventArgs e)
{
PrintDocument textPrintPage = new PrintDocument();
PrintDialog textPrintPreviewDialog = new PrintDialog();
if (textPrintPreviewDialog.ShowDialog() == true)
{
textPrintPage.Print();
}
}
private void textPrintPage_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x = e.MarginBounds.Left;
int y = e.MarginBounds.Top;
using (Font font = new Font("Times New Roman", 20))
{
string [] lines = new string[25];
for (int i = 0; i< lines.Length-1; i++)
{
lines[i] = dataFileText.GetLineText(i);
}
e.Graphics.DrawString("List of numbers", font, Brushes.Black, x, y + 20);
y += 40;
for (int i = 0; i < lines.Length - 1; i++)
{
e.Graphics.DrawString(lines[i], font, Brushes.Black, x, y);
y += 30;
}
}
e.HasMorePages = false;
}
推荐答案
private void printNumberList(object sender, RoutedEventArgs e)
{
PrintDocument textPrintPage = new PrintDocument();
textPrintPage.PrintPage += new EventHandler<PrintPageEventArgs>(textPrintPage_PrintPage);
PrintDialog textPrintPreviewDialog = new PrintDialog();
if (textPrintPreviewDialog.ShowDialog() == true)
{
textPrintPage.Print();
}
}
这篇关于代码生成的打印纸在纸上变成空白!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!