Sign in to follow this  
Stompy9999

[.net] Printing in C#

Recommended Posts

Stompy9999    792
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
SiCrane    11839
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

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