using System; using System.Collections.Generic; using System.ComponentModel; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.ComponentModel.TypeConverter; namespace TeamAAS.Communication.Attributes { public class ComPortListConverter : TypeConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true; public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true; // true=排他(不可手动输入),false=可输入 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { //获取电脑带有几个Com return new StandardValuesCollection(SerialPort.GetPortNames().ToList()); } } }