private void InitPrinter() { DataTable dtPrinter = new DataTable(); dtPrinter.Columns.Add("PrinterName", typeof(string)); System.Drawing.Printing.PrinterSettings.StringCollection printers = null; try { printers = System.Drawing.Printing.PrinterSettings.InstalledPrinters; } catch { // 有时访问 System.Drawing.Printing.PrinterSettings.InstalledPrinters,会报出“RPC服务器不可用”的错误,忽略此错 } dtPrinter.Rows.Add(dtPrinter.NewRow()); if (printers != null) { foreach (string strPrinterName in printers) { DataRow drRow = dtPrinter.NewRow(); drRow["PrinterName"] = strPrinterName; dtPrinter.Rows.Add(drRow); } } this.txtPrinterName.DataSource = dtPrinter.DefaultView; this.txtPrinterName.DisplayMember = "PrinterName"; this.txtPrinterName.ValueMember = "PrinterName"; }
/// <summary> /// 获取系统中已经安装的打印机列表 /// </summary> /// <returns>打印机列表</returns> public static string[] GetPrinterList() { try { System.Drawing.Printing.PrinterSettings.StringCollection lstPrinter = null; lstPrinter = System.Drawing.Printing.PrinterSettings.InstalledPrinters; if (lstPrinter.Count <= 0) { return(null); } string[] arrPrinterName = new string[lstPrinter.Count]; lstPrinter.CopyTo(arrPrinterName, 0); return(arrPrinterName); } catch (Exception ex) { LogManager.Instance.WriteLog("GlobalMethods.GetPrinterList", null, null, ex); return(null); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); System.Drawing.Printing.PrinterSettings.StringCollection printers = System.Drawing.Printing.PrinterSettings.InstalledPrinters; List <string> src = new List <string>(printers.Count); src.Add(Settings.Default.PrinterNull); foreach (string p in printers) { src.Add(p); } comboBoxPrinterName.DataSource = src; int selected = -1; if (!string.IsNullOrEmpty(Settings.Default.PrinterName)) { for (int i = 0; i < src.Count; i++) { if (src[i].Equals(Settings.Default.PrinterName)) { selected = i; break; } } } if (selected < 0 && src.Count > 0) { selected = 0; Settings.Default.PrinterName = src[0]; Settings.Default.Save(); } if (selected >= 0 && comboBoxPrinterName.Items.Count > 0) { comboBoxPrinterName.SelectedIndex = selected; } List <string> formats = new List <string>(); formats.Add("Code39"); formats.Add("Code128"); comboBoxBarcodeFormat.DataSource = formats; if (string.IsNullOrEmpty(Settings.Default.Barcode)) { comboBoxBarcodeFormat.SelectedIndex = 0; } else { comboBoxBarcodeFormat.SelectedItem = Settings.Default.Barcode; } numericUpDownWidth.Value = Settings.Default.PageWidth; numericUpDownHeight.Value = Settings.Default.PageHeight; string[] names = SerialPort.GetPortNames(); if (names != null && names.Length > 0) { comboBoxScannerSerialPort.Items.AddRange(names); if (!string.IsNullOrEmpty(Settings.Default.ScannerPort)) { comboBoxScannerSerialPort.SelectedItem = Settings.Default.ScannerPort; } } else { comboBoxScannerSerialPort.DataSource = null; } }
public FormSettings() { InitializeComponent(); Settings.Default.SettingChanging += Default_SettingChanging; #region Uygulama Durumu if (!Settings.Default.AppIsEnabled) { btnIsAppEnabled.Text = "AKTİF yap"; lblAppStatus.Text = "Uygulama PASİF"; pictureBoxAppStatus.Image = Resources.delete; } else { btnIsAppEnabled.Text = "PASİF yap"; lblAppStatus.Text = "Uygulama AKTİF"; pictureBoxAppStatus.Image = Resources.accept; } #endregion #region Kaynak ve Hedef Klasör Ayarları if (string.IsNullOrEmpty(Settings.Default.SourceFolder)) { Settings.Default.SourceFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache); Settings.Default.Save(); } if (string.IsNullOrEmpty(Settings.Default.DestinationFolder)) { Settings.Default.DestinationFolder = Path.Combine(@"C:\Program Files\Farmakode", Settings.Default.LatestPostFolderName); CacheBL.CheckSettings(); Settings.Default.Save(); } #endregion #region Yazıcı ayarları System.Drawing.Printing.PrinterSettings.StringCollection printerList = System.Drawing.Printing.PrinterSettings.InstalledPrinters; List <string> _printerList = new List <string>(); foreach (string printer in printerList) { _printerList.Add(printer); comboDefaultBarcodePrinter.Items.Add(printer); } if (!_printerList.Contains(Settings.Default.DefaultBarcodePrinter)) { comboDefaultBarcodePrinter.SelectedItem = LocalPrintServer.GetDefaultPrintQueue().FullName; } #endregion comboPCNO.Items.Clear(); foreach (var item in Common.GetPcNumberList()) { comboPCNO.Items.Add(item); } if (!string.IsNullOrEmpty(Settings.Default.PharmacyPCNO)) { comboPCNO.SelectedItem = Settings.Default.PharmacyPCNO; } this.Text = "Ayarlar | " + CacheBL.IPAddress; comboNotificationPosition.SelectedIndex = Settings.Default.NotificationPosition; }
public System.Drawing.Printing.PrinterSettings.StringCollection GetPrinterNameList() { System.Drawing.Printing.PrinterSettings.StringCollection sc = PrinterSettings.InstalledPrinters; return(sc); }