Jump to content

Recommended Posts

Posted

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...