![这里写图片描述](https://img-blog.csdn.net/20160311153206907)
窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace COM_TEST
{
public partial class Form1 : Form
{
CommBar commBar;
bool buttonBool = false;
public Form1()
{
InitializeComponent();
commBar = new CommBar();
CheckForIllegalCrossThreadCalls = false;
}
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox_Com.Items.Clear();
this.comboBox_Com.Items.Add("请选择COM口");
string[] comNames = commBar.GetComName();
for (int i = 0; i < comNames.Length; i++)
{
this.comboBox_Com.Items.Add(comNames[i]);
}
this.comboBox_Com.SelectedIndex = 0;
}
private