RichTextBox and C#

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
Hi everyone.

It's been a long time since I've coded in C#, and to help sharpen my skills I am trying to create a Notepad "clone", if you will. I've got it all down, except the printing part.

The code I have works, somewhat, but when I print more than one page it goes into a spooling loop and tries to spool hundreds upon hundreds of pages. It never seems to ever finish.

Here is the code:

privatevoid printToolStripMenuItem_Click(object sender, EventArgs e)
{
***printDialog1.Document =
this.printDocument1;
***printDocument1.DocumentName =
"Notepad Document";
***printDocument1.PrintPage +=
newPrintPageEventHandler(printDocument1_PrintPage);
***if (printDialog1.ShowDialog() == DialogResult.OK)
***{
******printDocument1.Print();
***}
}

privatevoid printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
***
int charCount = 0;
***
int lineCount = 0;
***
string strPrint = textBox1.Text;

***e.Graphics.MeasureString(strPrint, textBox1.Font,
e.MarginBounds.Size,
StringFormat.GenericTypographic, out charCount, out lineCount);
***e.Graphics.DrawString(strPrint, textBox1.Font,
Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic);

***strPrint = strPrint.Substring(charCount);

***
if (strPrint.Length > 0)
***{
******e.HasMorePages =
true;
***}
***
else
***
{
******e.HasMorePages =
false;
***}
}

Much appreciation to anyone that helps!


More...

View All Our Microsoft Related Feeds
 
Back
Top