Jump to content
  • Advertisement
Sign in to follow this  
Stompy9999

[.net] Printing in C#

This topic is 4712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently writing a text editor in C#, however, I've run into a bit of trouble. I'm trying to get the program to print the text that is currently in the text box. I have set up the printing dialog and actually sent a message to the printer. The problem is, I don't know how to specify what to print on the paper. So how exactly do I do that? Here is the code for the print event:
// Print out text file
private void Print_event(object sender, EventArgs e) 
{
	PrintDocument doc = new PrintDocument();
	PrintDialog print_dialog = new PrintDialog();
	print_dialog.AllowSomePages = true;
	print_dialog.ShowHelp = true;
	print_dialog.Document = doc;
			
	if(print_dialog.ShowDialog() == DialogResult.OK)
	{
		doc.Print();
	}
			
}

How do I specify what should be printed on the paper?

Share this post


Link to post
Share on other sites
Advertisement
Attach an event handler to the PrintPage event, which will have a PrintPageEventArgs as the event argument. The PrintPageEventArgs has a property Graphics, which you can use as any other surface. Just draw to that to show the output for each page.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!