ComPortListConverter.cs 836 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.IO.Ports;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using static System.ComponentModel.TypeConverter;
  9. namespace TeamAAS.Communication.Attributes
  10. {
  11. public class ComPortListConverter : TypeConverter
  12. {
  13. public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
  14. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true; // true=排他(不可手动输入),false=可输入
  15. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  16. {
  17. //获取电脑带有几个Com
  18. return new StandardValuesCollection(SerialPort.GetPortNames().ToList());
  19. }
  20. }
  21. }