// 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();
}
}
[.net] Printing in C#
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:
How do I specify what should be printed on the paper?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement