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 txtIP As System.Windows.Forms.TextBox 
    Friend WithEvents txtPort As System.Windows.Forms.TextBox 
    Friend WithEvents Label1 As System.Windows.Forms.Label 
    Friend WithEvents Label2 As System.Windows.Forms.Label 
    Friend WithEvents txtContent As System.Windows.Forms.TextBox 
    Friend WithEvents Label3 As System.Windows.Forms.Label 
    Friend WithEvents btnSend As System.Windows.Forms.Button 
     Private Sub InitializeComponent() 
        Me.txtIP = New System.Windows.Forms.TextBox() 
        Me.txtPort = New System.Windows.Forms.TextBox() 
        Me.Label1 = New System.Windows.Forms.Label() 
        Me.Label2 = New System.Windows.Forms.Label() 
        Me.btnSend = New System.Windows.Forms.Button() 
        Me.txtContent = New System.Windows.Forms.TextBox() 
        Me.Label3 = New System.Windows.Forms.Label() 
        Me.SuspendLayout() 
        ' 
        'txtIP 
        ' 
        Me.txtIP.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.txtIP.Location = New System.Drawing.Point(143, 16) 
        Me.txtIP.Name = "txtIP" 
        Me.txtIP.Size = New System.Drawing.Size(195, 26) 
        Me.txtIP.TabIndex = 0 
        Me.txtIP.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(143, 48) 
        Me.txtPort.Name = "txtPort" 
        Me.txtPort.Size = New System.Drawing.Size(113, 26) 
        Me.txtPort.TabIndex = 1 
        Me.txtPort.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(41, 24) 
        Me.Label1.Name = "Label1" 
        Me.Label1.Size = New System.Drawing.Size(92, 16) 
        Me.Label1.TabIndex = 2 
        Me.Label1.Text = "      地址" 
        ' 
        '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(48, 56) 
        Me.Label2.Name = "Label2" 
        Me.Label2.Size = New System.Drawing.Size(80, 16) 
        Me.Label2.TabIndex = 3 
        Me.Label2.Text = "通讯端口" 
        ' 
        'btnSend 
        ' 
        Me.btnSend.Location = New System.Drawing.Point(625, 96) 
        Me.btnSend.Name = "btnSend" 
        Me.btnSend.Size = New System.Drawing.Size(105, 24) 
        Me.btnSend.TabIndex = 4 
        Me.btnSend.Text = "接收数据" 
        ' 
        'txtContent 
        ' 
        Me.txtContent.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.txtContent.Location = New System.Drawing.Point(143, 99) 
        Me.txtContent.Name = "txtContent" 
        Me.txtContent.Size = New System.Drawing.Size(451, 22) 
        Me.txtContent.TabIndex = 5 
        Me.txtContent.Text = "" 
        ' 
        'Label3 
        ' 
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(136, Byte)) 
        Me.Label3.Location = New System.Drawing.Point(41, 102) 
        Me.Label3.Name = "Label3" 
        Me.Label3.Size = New System.Drawing.Size(92, 16) 
        Me.Label3.TabIndex = 6 
        Me.Label3.Text = "传送文字" 
        ' 
        'Form1 
        ' 
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) 
        Me.ClientSize = New System.Drawing.Size(747, 157) 
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.txtContent, Me.btnSend, Me.Label2, Me.Label1, Me.txtPort, Me.txtIP}) 
        Me.Name = "Form1" 
        Me.Text = "Form1" 
        Me.ResumeLayout(False) 
 
    End Sub 
 
#End Region 
 
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click 
        Dim intPort As Integer 
        Dim strIP As String 
        Dim myUdpDataSend As UdpDataSend 
 
        Dim strErrMessage As String 
 
        strIP = txtIP.Text 
        intPort = Integer.Parse(txtPort.Text) 
 
        myUdpDataSend = New UdpDataSend(strIP, intPort) 
        myUdpDataSend.SetSendMessage = txtContent.Text 
        myUdpDataSend.SendData() 
        strErrMessage = myUdpDataSend.GetMessage 
        If Not strErrMessage.Length > 0 Then 
            MessageBox.Show("数据传送成功 !! ", "UDP数据传送消息...") 
        Else 
            MessageBox.Show(strErrMessage, "UDP数据传送错误消息...") 
        End If 
 
    End Sub 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
 
    End Sub 
End Class