Game Development Reference
In-Depth Information
// Handle empty lines
lines = lines == 0 ? 1 : lines;
return lines;
Using the new SimplePrintDocument class is easy; instantiate it as you did with
PrintDocument and call the Print() method!
Supporting Printer Selection
We currently have the logic for printing support implemented, so the next logical
step is to provide the ability to select a printer using the standard Windows Print
dialog. Right now, you are simply calling the print method on the document, but
in a real world application, you let the user select the printer she wants to use and
also support the ability to cancel printing. Using the PrintDialog class, we can pro-
vide this functionality to users. Attach the print document to the Document proper-
ty of the dialog and show the dialog as normal. If the dialog returns successfully,
call the print method of the document. The following code shows a sample imple-
mentation of printer selection.
private void PrintButton_Click(object sender, EventArgs e)
using (StringReader inputText = new StringReader(PrintTextField.Text))
SimplePrintDocument printDocument = new SimplePrintDocument(inputText,
PrintDialog printDialog = new PrintDialog();
printDialog.Document = printDocument;
if (printDialog.ShowDialog() == DialogResult.OK)
Figure 21.1 shows the printer selection dialog in action.
Search Nedrilad ::

Custom Search