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;
}