www.pudn.com > UpdReceive_UdpSend.rar > Form1.vb


Public Class Form1 
    Inherits System.Windows.Forms.Form 
 
#Region " Windows Form 砞璸ㄣ玻ネ祘Α絏 " 
 
    Public Sub New() 
        MyBase.New() 
 
        '㊣ Windows Form 砞璸ㄣゲ璶兜 
        InitializeComponent() 
 
        ' InitializeComponent() ㊣ぇ┮Τ﹍砞﹚ 
 
    End Sub 
 
    'Form 滦糶 Dispose 睲埃じン睲虫 
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 
        If disposing Then 
            If Not (components Is Nothing) Then 
                components.Dispose() 
            End If 
        End If 
        MyBase.Dispose(disposing) 
    End Sub 
 
    ' Windows Form 砞璸ㄣゲ璶兜 
    Private components As System.ComponentModel.IContainer 
 
    '猔種:  Windows Form 砞璸ㄣ┮惠祘 
    '眤ㄏノ Windows Form 砞璸ㄣ秈︽э 
    '叫づㄏノ祘Α絏絪胯竟ㄓэ硂ㄇ祘 
    Friend WithEvents Label2 As System.Windows.Forms.Label 
    Friend WithEvents txtPort As System.Windows.Forms.TextBox 
    Friend WithEvents Label1 As System.Windows.Forms.Label 
    Friend WithEvents btnReceive As System.Windows.Forms.Button 
    Friend WithEvents txtReceiveData As System.Windows.Forms.TextBox 
    Friend WithEvents lblMessage As System.Windows.Forms.Label 
    Friend WithEvents Label4 As System.Windows.Forms.Label 
     Private Sub InitializeComponent() 
        Me.Label2 = New System.Windows.Forms.Label() 
        Me.txtPort = New System.Windows.Forms.TextBox() 
        Me.btnReceive = New System.Windows.Forms.Button() 
        Me.txtReceiveData = New System.Windows.Forms.TextBox() 
        Me.Label1 = New System.Windows.Forms.Label() 
        Me.lblMessage = New System.Windows.Forms.Label() 
        Me.Label4 = New System.Windows.Forms.Label() 
        Me.SuspendLayout() 
        ' 
        'Label2 
        ' 
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.Label2.Location = New System.Drawing.Point(92, 48) 
        Me.Label2.Name = "Label2" 
        Me.Label2.Size = New System.Drawing.Size(72, 16) 
        Me.Label2.TabIndex = 5 
        Me.Label2.Text = "    端口" 
        ' 
        'txtPort 
        ' 
        Me.txtPort.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.txtPort.Location = New System.Drawing.Point(174, 40) 
        Me.txtPort.Name = "txtPort" 
        Me.txtPort.Size = New System.Drawing.Size(113, 26) 
        Me.txtPort.TabIndex = 4 
        Me.txtPort.Text = "" 
        ' 
        'btnReceive 
        ' 
        Me.btnReceive.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.btnReceive.Location = New System.Drawing.Point(563, 80) 
        Me.btnReceive.Name = "btnReceive" 
        Me.btnReceive.Size = New System.Drawing.Size(144, 32) 
        Me.btnReceive.TabIndex = 6 
        Me.btnReceive.Text = "数据接收" 
        ' 
        'txtReceiveData 
        ' 
        Me.txtReceiveData.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.txtReceiveData.Location = New System.Drawing.Point(174, 88) 
        Me.txtReceiveData.Name = "txtReceiveData" 
        Me.txtReceiveData.Size = New System.Drawing.Size(369, 22) 
        Me.txtReceiveData.TabIndex = 7 
        Me.txtReceiveData.Text = "" 
        ' 
        'Label1 
        ' 
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.Label1.Location = New System.Drawing.Point(31, 90) 
        Me.Label1.Name = "Label1" 
        Me.Label1.Size = New System.Drawing.Size(143, 16) 
        Me.Label1.TabIndex = 8 
        Me.Label1.Text = "          数据内容" 
        ' 
        'lblMessage 
        ' 
        Me.lblMessage.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.lblMessage.Location = New System.Drawing.Point(174, 128) 
        Me.lblMessage.Name = "lblMessage" 
        Me.lblMessage.Size = New System.Drawing.Size(348, 24) 
        Me.lblMessage.TabIndex = 9 
        ' 
        'Label4 
        ' 
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.Label4.Location = New System.Drawing.Point(72, 128) 
        Me.Label4.Name = "Label4" 
        Me.Label4.Size = New System.Drawing.Size(92, 16) 
        Me.Label4.TabIndex = 10 
        Me.Label4.Text = "接受消息" 
        ' 
        'Form1 
        ' 
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) 
        Me.ClientSize = New System.Drawing.Size(757, 165) 
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.lblMessage, Me.Label1, Me.txtReceiveData, Me.btnReceive, Me.Label2, Me.txtPort}) 
        Me.Name = "Form1" 
        Me.Text = "Form1" 
        Me.ResumeLayout(False) 
 
    End Sub 
 
#End Region 
 
    Private Sub btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click 
 
        Dim myUdpDataReceive As UdpDataReceive 
        Dim intPort As Integer 
        Dim strErrMessage As String 
        intPort = txtPort.Text 
        myUdpDataReceive = New UdpDataReceive(intPort) 
        lblMessage.Text = "等待接收消息 ......." 
 
        myUdpDataReceive.AcceptData() 
        strErrMessage = myUdpDataReceive.GetMessage 
        If Not strErrMessage.Length  > 0 Then 
            txtReceiveData.Text = myUdpDataReceive.GetReceiveData 
        Else 
            MessageBox.Show(strErrMessage) 
        End If 
 
        lblMessage.Text = "消息接收完成 ......." 
    End Sub 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
 
    End Sub 
End Class