[C#] //下面括號內的自己翻譯添加進去的 private void PopulateInstalledPrintersCombo() { // Add list of installed printers found to the combo box.(將系統中所有的打機加入列表框) // The pkInstalledPrinters string will be used to provide the display string.(列表框中顯示的字串由pkInstalledPrinters提供) foreach(String pkInstalledPrinters in PrinterSettings.InstalledPrinters) { comboInstalledPrinters.Items.Add(pkInstalledPrinters); } }
// Set the printer to a printer in the combo box when the selection changes.(當列表框改變時設置選擇的打印機)
if (comboInstalledPrinters.SelectedIndex != -1) { // The combo box's Text property returns the selected item's text, which is the printer name.(將選擇的打印機名在列表框中顯示) printDoc.PrinterSettings.PrinterName= comboInstalledPrinters.Text; }
}
看了MSDN的說明,懂多了吧,下面是我寫練習完整代碼.
//程序說明:將系統中的所有打印機在列表框中列出 //程序變量: PrintDocument prtdoc、string strDefaultPrinter //編寫人:蠶蛹([email protected]) //日期:2003-03-20 using System; using System.Drawing; using System.Drawing.Printing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;