private void SettingsForm_Load(object sender, EventArgs e) { try { string[] serialPorts = SerialPort.GetPortNames(); foreach (string serialPort in serialPorts) { comboPorts.Items.Add(serialPort); cmbBoxScannerPort.Items.Add(serialPort); } if (CommBase.IsPortAvailable(_dllSettings.ComPort)) { comboPorts.SelectedItem = _dllSettings.ComPortName; } else if (comboPorts.Items.Count > 0) { comboPorts.SelectedIndex = 0; } // 打开设置窗口时扫码枪串口已经被打开了,故无需判断串口是否可用 cmbBoxScannerPort.SelectedItem = _mainSettings.ScannerPortName; comboHardware.SelectedIndex = _dllSettings.HardwareIndexInt; comboBaud.SelectedIndex = _dllSettings.BaudRateIndex; cmbBoxScannerBaud.SelectedIndex = _mainSettings.ScannerBaudRateIndex; chkBoxUseSerialScanner.Checked = _mainSettings.UseSerialScanner; cmbBoxScannerPort.Enabled = chkBoxUseSerialScanner.Checked; cmbBoxScannerBaud.Enabled = chkBoxUseSerialScanner.Checked; foreach (string item in DllSettings.ProtocolNames) { comboProtocol.Items.Add(item); } comboProtocol.SelectedIndex = _dllSettings.ProtocolIndexInt; comboInitialize.SelectedIndex = !_dllSettings.DoInitialization ? 1 : 0; foreach (string item in DllSettings.StandardNames) { comboStandard.Items.Add(item); } comboStandard.SelectedIndex = _dllSettings.StandardIndexInt; if (_dllSettings.AutoDetect) { checkBoxAutoDetect.Checked = true; } else { checkBoxAutoDetect.Checked = false; } txtTesterName.Text = _mainSettings.TesterName; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }