[.net] Printing in C#

Started by
1 comment, last by Stompy9999 18 years, 9 months ago
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?
-----------------------------Play Stompy's Revenge! Now!
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.
Thanks!
-----------------------------Play Stompy's Revenge! Now!

This topic is closed to new replies.

Advertisement