Sign in to follow this  

[.net] Printing in C#

This topic is 4545 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
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

This topic is 4545 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this