Пример #1
0
        private void AddPorts()
        {
            if (_ComPortInfoList == null || _ComPortInfoList.Count == 0)
            {
                _ComPortInfoList = COMPortInfo.GetCOMPortsInfo();
            }
            Graphics ComboGraphics = SerialPortCombo.CreateGraphics();
            Font     ComboFont     = SerialPortCombo.Font;
            int      MaxWidth      = 0;

            foreach (COMPortInfo ComPort in _ComPortInfoList)
            {
                string s = ComPort.Name + " - " + ComPort.Description;
                SerialPortCombo.Items.Add(s);
                int VertScrollBarWidth = (SerialPortCombo.Items.Count > SerialPortCombo.MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;
                int DropDownWidth      = (int)ComboGraphics.MeasureString(s, ComboFont).Width + VertScrollBarWidth;
                if (MaxWidth < DropDownWidth)
                {
                    SerialPortCombo.DropDownWidth = DropDownWidth;
                    MaxWidth = DropDownWidth;
                }
            }
            if (SerialPortCombo.Items.Count > 0)
            {
                SerialPortCombo.SelectedIndex = 0;
            }
            Log.PrintLog(this, _ComPortInfoList.Count.ToString() + " serial ports found.", LogDetailLevel.LogRelevant);
        }
Пример #2
0
        private void AddPorts()
        {
            _ComPortInfoList = _mTKSerialPort.ComPortList;
            Graphics ComboGraphics = SerialPortCombo.CreateGraphics();
            Font     ComboFont     = SerialPortCombo.Font;
            int      MaxWidth      = 0;

            foreach (COMPortInfo ComPort in _ComPortInfoList)
            {
                string s = ComPort.Name + " - " + ComPort.Description;
                SerialPortCombo.Items.Add(s);
                int VertScrollBarWidth = (SerialPortCombo.Items.Count > SerialPortCombo.MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;
                int DropDownWidth      = (int)ComboGraphics.MeasureString(s, ComboFont).Width + VertScrollBarWidth;
                if (MaxWidth < DropDownWidth)
                {
                    SerialPortCombo.DropDownWidth = DropDownWidth;
                    MaxWidth = DropDownWidth;
                }
            }
            if (SerialPortCombo.Items.Count > 0)
            {
                SerialPortCombo.SelectedIndex = 0;
            }
        }