SerialPortCombox.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Windows.Forms;
  3. using System.IO.Ports;
  4. namespace UAS_LabelMachine.CustomControl
  5. {
  6. public partial class SerialPortCombox : UserControl
  7. {
  8. public SerialPortCombox()
  9. {
  10. InitializeComponent();
  11. }
  12. public override string Text
  13. {
  14. get
  15. {
  16. return ComCombox.Text;
  17. }
  18. set
  19. {
  20. ComCombox.Text = value;
  21. }
  22. }
  23. public string SelectedText
  24. {
  25. get
  26. {
  27. return ComCombox.SelectedText;
  28. }
  29. set
  30. {
  31. ComCombox.SelectedText = value;
  32. }
  33. }
  34. public object SelectedValue
  35. {
  36. get
  37. {
  38. return ComCombox.SelectedValue;
  39. }
  40. set
  41. {
  42. ComCombox.SelectedValue = value;
  43. }
  44. }
  45. public object Items
  46. {
  47. get
  48. {
  49. return ComCombox.Items;
  50. }
  51. }
  52. private void SerialPortCombox_Load(object sender, EventArgs e)
  53. {
  54. ComCombox.Items.AddRange(SerialPort.GetPortNames());
  55. foreach (var item in ComCombox.Items)
  56. {
  57. if (item.ToString() == Properties.Settings.Default.PortName)
  58. {
  59. ComCombox .SelectedIndex= ComCombox.Items.IndexOf(item);
  60. return;
  61. }
  62. }
  63. }
  64. }
  65. }