FrmReceiveMessage.vb
资源名称:08.zip [点击查看]
上传用户:ynjin1970
上传日期:2014-10-13
资源大小:6438k
文件大小:12k
源码类别:
中间件编程
开发平台:
Visual C++
- 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 Label7 As System.Windows.Forms.Label
- Friend WithEvents txtQueueName As System.Windows.Forms.TextBox
- Friend WithEvents btnReceive As System.Windows.Forms.Button
- Friend WithEvents txtAge As System.Windows.Forms.TextBox
- Friend WithEvents Label6 As System.Windows.Forms.Label
- <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.btnReceive = 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.txtAge = New System.Windows.Forms.TextBox()
- Me.Label6 = New System.Windows.Forms.Label()
- Me.GroupBox1.SuspendLayout()
- Me.GroupBox2.SuspendLayout()
- Me.GroupBox3.SuspendLayout()
- Me.SuspendLayout()
- '
- 'GroupBox1
- '
- Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label6, Me.txtAge, 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.Enabled = False
- 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.Enabled = False
- 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.Enabled = False
- 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 = ""
- '
- '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.Enabled = False
- 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(1999, 1, 1, 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.Enabled = False
- 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 = "姓名"
- '
- 'btnReceive
- '
- Me.btnReceive.Dock = System.Windows.Forms.DockStyle.Right
- Me.btnReceive.Location = New System.Drawing.Point(309, 17)
- Me.btnReceive.Name = "btnReceive"
- Me.btnReceive.Size = New System.Drawing.Size(56, 36)
- Me.btnReceive.TabIndex = 0
- Me.btnReceive.Text = "接受"
- '
- 'GroupBox3
- '
- Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtQueueName, Me.Label7, Me.btnReceive})
- 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(96, 24)
- Me.txtQueueName.Name = "txtQueueName"
- Me.txtQueueName.Size = New System.Drawing.Size(104, 21)
- Me.txtQueueName.TabIndex = 4
- Me.txtQueueName.Text = "PersonInfo"
- '
- 'Label7
- '
- Me.Label7.AutoSize = True
- Me.Label7.Location = New System.Drawing.Point(16, 32)
- Me.Label7.Name = "Label7"
- Me.Label7.Size = New System.Drawing.Size(66, 14)
- Me.Label7.TabIndex = 3
- Me.Label7.Text = "私有队列名"
- '
- 'txtAge
- '
- Me.txtAge.Enabled = False
- Me.txtAge.Location = New System.Drawing.Point(272, 64)
- Me.txtAge.Name = "txtAge"
- Me.txtAge.Size = New System.Drawing.Size(56, 21)
- Me.txtAge.TabIndex = 13
- Me.txtAge.Text = ""
- '
- 'Label6
- '
- Me.Label6.AutoSize = True
- Me.Label6.Location = New System.Drawing.Point(232, 64)
- Me.Label6.Name = "Label6"
- Me.Label6.Size = New System.Drawing.Size(29, 14)
- Me.Label6.TabIndex = 14
- Me.Label6.Text = "年龄"
- '
- '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 btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click
- Dim person As PersonInfo.Person
- Dim mq As Messaging.MessageQueue
- Dim mqMessage As Messaging.Message
- Try
- '清空已有信息
- Me.TxtName.Text = ""
- Me.txtBirthPlace.Text = ""
- Me.txtSalary.Text = ""
- Me.rbMale.Checked = False
- Me.rbFemale.Checked = False
- Me.txtAge.Text = ""
- '定义MessageQueue对象,并指向特定的队列,独占访问
- If Not Messaging.MessageQueue.Exists(".Private$" & Me.txtQueueName.Text) Then
- Messaging.MessageQueue.Create(".Private$" & Me.txtQueueName.Text)
- End If
- mq = New Messaging.MessageQueue(".Private$" & Me.txtQueueName.Text, True)
- mq.Formatter = New Messaging.XmlMessageFormatter(New System.Type() {GetType(PersonInfo.Person)}) '设置消息类型,
- 'mq.Formatter = New Messaging.BinaryMessageFormatter() '设置消息类型
- Me.btnReceive.Enabled = False
- mqMessage = mq.Receive(New TimeSpan(0, 0, 5)) '接受消息,5秒仍然未接受到消息将超时
- person = CType(mqMessage.Body, PersonInfo.Person) ' 将消息转化成Person类型
- '显示接受的个人信息
- Me.TxtName.Text = person.Name
- Me.dtpBirthDate.Value = person.BirthDate
- Me.txtBirthPlace.Text = person.BirthPlace
- Me.txtSalary.Text = person.Salary
- If person.Sex = True Then
- Me.rbMale.Checked = True
- Else
- Me.rbFemale.Checked = True
- End If
- Me.txtAge.Text = person.Age
- mq.Close()
- Me.btnReceive.Enabled = True
- Catch ex As Exception
- Me.btnReceive.Enabled = True
- mq.Close()
- MsgBox("错误,没有消息或超时!")
- End Try
- End Sub
- End Class