//获取系统中的串口并加入到下拉框中 cbCashBoxPort.Items.Clear(); string[] ports = System.IO.Ports.SerialPort.GetPortNames(); if (ports != null) { foreach (string port in ports) { cbCashBoxPort.AddItem(port, port); } } //获取系统中的并口并加入到下拉框中 using (ManagementObjectSearcher seacher = new ManagementObjectSearcher("select * from Win32_ParallelPort")) { foreach (ManagementObject item in seacher.Get()) { PropertyData data = item.Properties["Caption"]; cbCashBoxPort.AddItem(data.Value.ToString(),data.Value.ToString()); } }