| PrintDocument prtdoc = new PrintDocument(); string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;//获取默认的打印机名 |
| [C#] [Serializable] [ComVisible(false)] public static PrinterSettings.StringCollection InstalledPrinters {get;} |
| 异常类型 | 条件 |
| Win32Exception | 未能枚举可用的打印机 |
| [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); } } private void comboInstalledPrinters_SelectionChanged(object sender, System.EventArgs e) { // 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; } } |