[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Let the user select a printer and then send a printout directly to it in C#

[Let the user select a printer and then send a printout directly to it in C#]
When it starts, the program uses the following code to list the available printers in a ComboBox.

// List the available printers. private void Form1_Load(object sender, EventArgs e) { foreach (string printer in PrinterSettings.InstalledPrinters) cboPrinter.Items.Add(printer); }

This code loops through the System.Drawing.Printing.PrinterSettings.InstalledPrinters collection, adding each printer's name to the ComboBox.

When the user selects a printer and clicks Print, the following code sends the printout to the selected printer.

// Print. private void btnPrint_Click(object sender, EventArgs e) { // Select the printer. pdocSmiley.PrinterSettings.PrinterName = cboPrinter.Text; // Print. pdocSmiley.Print(); }

This code sets the PrintDocument object's printer name to the selected printer and then calls the PrintDocument object's Print method to generate the printout.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.