⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmsendmessage.vb

📁 VC实现等值线编成的COM组件的源程序代码
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    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 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents dtpBirthDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents TxtName As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents rbMale As System.Windows.Forms.RadioButton
    Friend WithEvents rbFemale As System.Windows.Forms.RadioButton
    Friend WithEvents txtSalary As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtBirthPlace As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents txtMachineName As System.Windows.Forms.TextBox
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
    Friend WithEvents txtQueueName As System.Windows.Forms.TextBox
    Friend WithEvents btnSend As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.txtBirthPlace = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.rbMale = New System.Windows.Forms.RadioButton()
        Me.rbFemale = New System.Windows.Forms.RadioButton()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.txtSalary = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.dtpBirthDate = New System.Windows.Forms.DateTimePicker()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.TxtName = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.btnSend = New System.Windows.Forms.Button()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.txtQueueName = New System.Windows.Forms.TextBox()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.txtMachineName = New System.Windows.Forms.TextBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtBirthPlace, Me.Label5, Me.GroupBox2, Me.Label4, Me.txtSalary, Me.Label3, Me.dtpBirthDate, Me.Label2, Me.TxtName, Me.Label1})
        Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(368, 277)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "个人信息"
        '
        'txtBirthPlace
        '
        Me.txtBirthPlace.Location = New System.Drawing.Point(80, 192)
        Me.txtBirthPlace.Name = "txtBirthPlace"
        Me.txtBirthPlace.Size = New System.Drawing.Size(264, 21)
        Me.txtBirthPlace.TabIndex = 12
        Me.txtBirthPlace.Text = "中国上海市虹口区"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(15, 192)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(54, 14)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "出生地址"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.rbMale, Me.rbFemale})
        Me.GroupBox2.Location = New System.Drawing.Point(80, 96)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(144, 40)
        Me.GroupBox2.TabIndex = 10
        Me.GroupBox2.TabStop = False
        '
        'rbMale
        '
        Me.rbMale.Checked = True
        Me.rbMale.Location = New System.Drawing.Point(24, 8)
        Me.rbMale.Name = "rbMale"
        Me.rbMale.Size = New System.Drawing.Size(40, 24)
        Me.rbMale.TabIndex = 8
        Me.rbMale.TabStop = True
        Me.rbMale.Text = "男"
        '
        'rbFemale
        '
        Me.rbFemale.Location = New System.Drawing.Point(96, 8)
        Me.rbFemale.Name = "rbFemale"
        Me.rbFemale.Size = New System.Drawing.Size(32, 24)
        Me.rbFemale.TabIndex = 9
        Me.rbFemale.Text = "女"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(40, 104)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(29, 14)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "性别"
        '
        'txtSalary
        '
        Me.txtSalary.Location = New System.Drawing.Point(80, 152)
        Me.txtSalary.Name = "txtSalary"
        Me.txtSalary.Size = New System.Drawing.Size(56, 21)
        Me.txtSalary.TabIndex = 5
        Me.txtSalary.Text = "6000"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(27, 152)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(42, 14)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "月工资"
        '
        'dtpBirthDate
        '
        Me.dtpBirthDate.Location = New System.Drawing.Point(80, 64)
        Me.dtpBirthDate.Name = "dtpBirthDate"
        Me.dtpBirthDate.Size = New System.Drawing.Size(144, 21)
        Me.dtpBirthDate.TabIndex = 3
        Me.dtpBirthDate.Value = New Date(1974, 2, 16, 0, 0, 0, 0)
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(15, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 14)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "出生日期"
        '
        'TxtName
        '
        Me.TxtName.Location = New System.Drawing.Point(80, 24)
        Me.TxtName.Name = "TxtName"
        Me.TxtName.Size = New System.Drawing.Size(144, 21)
        Me.TxtName.TabIndex = 1
        Me.TxtName.Text = "张三"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(40, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(29, 14)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "姓名"
        '
        'btnSend
        '
        Me.btnSend.Dock = System.Windows.Forms.DockStyle.Right
        Me.btnSend.Location = New System.Drawing.Point(309, 17)
        Me.btnSend.Name = "btnSend"
        Me.btnSend.Size = New System.Drawing.Size(56, 36)
        Me.btnSend.TabIndex = 0
        Me.btnSend.Text = "发送"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtQueueName, Me.Label7, Me.txtMachineName, Me.Label6, Me.btnSend})
        Me.GroupBox3.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.GroupBox3.Location = New System.Drawing.Point(0, 221)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(368, 56)
        Me.GroupBox3.TabIndex = 2
        Me.GroupBox3.TabStop = False
        '
        'txtQueueName
        '
        Me.txtQueueName.Location = New System.Drawing.Point(192, 24)
        Me.txtQueueName.Name = "txtQueueName"
        Me.txtQueueName.Size = New System.Drawing.Size(72, 21)
        Me.txtQueueName.TabIndex = 4
        Me.txtQueueName.Text = "PersonInfo"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(120, 32)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(66, 14)
        Me.Label7.TabIndex = 3
        Me.Label7.Text = "私有队列名"
        '
        'txtMachineName
        '
        Me.txtMachineName.Location = New System.Drawing.Point(56, 24)
        Me.txtMachineName.Name = "txtMachineName"
        Me.txtMachineName.Size = New System.Drawing.Size(56, 21)
        Me.txtMachineName.TabIndex = 2
        Me.txtMachineName.Text = "CE-ZDQ"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(8, 32)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(42, 14)
        Me.Label6.TabIndex = 1
        Me.Label6.Text = "机器名"
        '
        'ErrorProvider1
        '
        Me.ErrorProvider1.DataMember = Nothing
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(368, 277)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox3, Me.GroupBox1})
        Me.Name = "Form1"
        Me.Text = "发送消息"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub txtSalary_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSalary.Validated
        '清除错误提示
        ErrorProvider1.SetError(txtSalary, "")
    End Sub


    Private Sub txtSalary_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSalary.Validating
        If Not IsNumeric(txtSalary.Text) Then

            ' 取消事件,选中需要修改的文字
            e.Cancel = True
            txtSalary.Select(0, txtSalary.Text.Length)
            ' 设置显示的错误信息
            Me.ErrorProvider1.SetError(txtSalary, "工资必须为数值型!")
        End If
    End Sub

    
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim person As PersonInfo.Person
        Dim mq As Messaging.MessageQueue
        Dim mqMessage As Messaging.Message

        Try
            person = New PersonInfo.Person()

            '--取得人员的信息,存储---------------------
            person.Name = Me.TxtName.Text
            person.BirthDate = Me.dtpBirthDate.Value
            If Me.rbMale.Checked = True Then
                person.Sex = True
            Else
                person.Sex = False
            End If
            person.Salary = CDec(Me.txtSalary.Text)
            person.BirthPlace = Me.txtBirthPlace.Text

            '定义MessageQueue对象,并指向特定的队列,由于允许脱机发送,所以用FormatName指定Path
            mq = New Messaging.MessageQueue("FormatName:DIRECT=OS:" & Me.txtMachineName.Text & "\Private$\" & Me.txtQueueName.Text)

            '定义并设置需要发送的Message
            mqMessage = New Messaging.Message()
            mqMessage.Body = person  '消息具体类容
            mqMessage.Formatter = New Messaging.XmlMessageFormatter() '消息发送格式
            mqMessage.Label = "个人信息:" & person.Name  '设置Message标签
            mqMessage.TimeToReachQueue = New TimeSpan(0, 0, 30) '30秒未到达目标的话,将超时

            '超时处理,发送一个消息到本地的私有队列:AckPerson
            mqMessage.AcknowledgeType = Messaging.AcknowledgeTypes.NotAcknowledgeReachQueue
            If Not Messaging.MessageQueue.Exists(".\Private$\AckPerson") Then
                Messaging.MessageQueue.Create(".\Private$\AckPerson")
            End If
            mqMessage.AdministrationQueue = New Messaging.MessageQueue(".\Private$\AckPerson")

            '发送消息到指定的队列
            mq.Send(mqMessage)
            mq.Close()
            MsgBox("OK")
        Catch ex As Exception
            mq.Close()
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -