comSelectInit()

来源:互联网 发布:工业控制网络的特点 编辑:程序博客网 时间:2024/06/04 18:48

在窗体加载方法中定义串口选择初始化函数时发现了一个问题

private void comSelectInit(){    //检查是否含有串口    string[] str = System.IO.Ports.SerialPort.GetPortNames();    if (str == null)    {        MessageBox.Show("没有可使用的串口!", "Error");        return;    }    else foreach (string s in str) MessageBox.Show(s);    //添加串口项目    foreach(string s in System.IO.Ports.SerialPort.GetPortNames())    {        comSelect.Items.Add(s);    }    //串口设置默认选择项    //comSelect.Items.Add("hehe");    comSelect.SelectedIndex = 0;}

0 0
原创粉丝点击