Imports System.IO.Ports
Imports System.Text

Public Class Form1

    '声明一个委派类，并声明符合函数参数有一个，而其类型是字符串
    Delegate Sub SetTextCallback(ByVal InputString As String)

    '**************************************************************
    '窗体的Load事件中先将所有的通信端口先列出来
    '将通信端口排序，并将第一个通信端口设为默认值
    '**************************************************************

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each sp As String In SerialPort.GetPortNames()
            cmbCOM.Items.Add(sp)
        Next
        cmbCOM.Sorted = True   '排序
        cmbCOM.SelectedIndex = 0 '第一个默认排序
    End Sub
End Class
