通过调用windows\system32\mqoa.dll 这个Message Queuing ActiveX Interface API函数就可以做到;
1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6using MSMQ;
7namespace MyTest
8{
9 /**//// <summary>
10 /// Form2 的摘要说明。
11 /// </summary>
12 public class Form2 : System.Windows.Forms.Form
13 {
14 Forms#region Forms
15 private System.Windows.Forms.GroupBox groupBox1;
16 private System.Windows.Forms.Label label1;
17 private System.Windows.Forms.Label label2;
18 private System.Windows.Forms.Label label3;
19 private System.Windows.Forms.GroupBox groupBox2;
20 private System.Windows.Forms.TextBox txthost;
21 private System.Windows.Forms.TextBox txtpath;
22 private System.Windows.Forms.RadioButton trans1;
23 private System.Windows.Forms.RadioButton trans2;
24 private System.Windows.Forms.GroupBox groupBox3;
25 private System.Windows.Forms.Label label4;
26 private System.Windows.Forms.Button button1;
27 private System.Windows.Forms.Label label5;
28 private System.Windows.Forms.Button button2;
29 private System.Windows.Forms.TextBox txtmsg;
30 private System.Windows.Forms.TextBox txtrece;
31 /**//// <summary>
32 /// 必需的设计器变量。
33 /// </summary>
34 private System.ComponentModel.Container components = null;
35
36 public Form2()
37 {
38 //
39 // Windows 窗体设计器支持所必需的
40 //
41 InitializeComponent();
42
43 //
44 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
45 //
46 }
47
48 /**//// <summary>
49 /// 清理所有正在使用的资源。
50 /// </summary>
51 protected override void Dispose( bool disposing )
52 {
53 if( disposing )
54 {
55 if(components != null)
56 {
57 components.Dispose();
58 }
59 }
60 base.Dispose( disposing );
61 }
62 #endregion
63
64 Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
65 /**//// <summary>
66 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
67 /// 此方法的内容。
68 /// </summary>
69 private void InitializeComponent()
70 {
71 this.groupBox1 = new System.Windows.Forms.GroupBox();
72 this.groupBox2 = new System.Windows.Forms.GroupBox();
73 this.trans2 = new System.Windows.Forms.RadioButton();
74 this.trans1 = new System.Windows.Forms.RadioButton();
75 this.label3 = new System.Windows.Forms.Label();
76 this.txtpath = new System.Windows.Forms.TextBox();
77 this.label2 = new System.Windows.Forms.Label();
78 this.txthost = new System.Windows.Forms.TextBox();
79 this.label1 = new System.Windows.Forms.Label();
80 this.groupBox3 = new System.Windows.Forms.GroupBox();
81 this.button2 = new System.Windows.Forms.Button();
82 this.txtrece = new System.Windows.Forms.TextBox();
83 this.label5 = new System.Windows.Forms.Label();
84 this.button1 = new System.Windows.Forms.Button();
85 this.txtmsg = new System.Windows.Forms.TextBox();
86 this.label4 = new System.Windows.Forms.Label();
87 this.groupBox1.SuspendLayout();
88 this.groupBox2.SuspendLayout();
89 this.groupBox3.SuspendLayout();
90 this.SuspendLayout();
91 //
92 // groupBox1
93 //
94 this.groupBox1.Controls.Add(this.groupBox2);
95 this.groupBox1.Controls.Add(this.label3);
96 this.groupBox1.Controls.Add(this.txtpath);
97 this.groupBox1.Controls.Add(this.label2);
98 this.groupBox1.Controls.Add(this.txthost);
99 this.groupBox1.Controls.Add(this.label1);
100 this.groupBox1.Location = new System.Drawing.Point(8, 8);
101 this.groupBox1.Name = "groupBox1";
102 this.groupBox1.Size = new System.Drawing.Size(352, 120);
103 this.groupBox1.TabIndex = 0;
104 this.groupBox1.TabStop = false;
105 this.groupBox1.Text = "MSMQ Configuration";
106 //
107 // groupBox2
108 //
109 this.groupBox2.Controls.Add(this.trans2);
110 this.groupBox2.Controls.Add(this.trans1);
111 this.groupBox2.Location = new System.Drawing.Point(104, 72);
112 this.groupBox2.Name = "groupBox2";
113 this.groupBox2.Size = new System.Drawing.Size(144, 40);
114 this.groupBox2.TabIndex = 5;
115 this.groupBox2.TabStop = false;
116 //
117 // trans2
118 //
119 this.trans2.Checked = true;
120 this.trans2.Location = new System.Drawing.Point(72, 16);
121 this.trans2.Name = "trans2";
122 this.trans2.Size = new System.Drawing.Size(64, 19);
123 this.trans2.TabIndex = 1;
124 this.trans2.TabStop = true;
125 this.trans2.Text = "true";
126 //
127 // trans1
128 //
129 this.trans1.Location = new System.Drawing.Point(8, 16);
130 this.trans1.Name = "trans1";
131 this.trans1.Size = new System.Drawing.Size(48, 19);
132 this.trans1.TabIndex = 0;
133 this.trans1.Text = "true";
134 //
135 // label3
136 //
137 this.label3.Location = new System.Drawing.Point(8, 88);
138 this.label3.Name = "label3";
139 this.label3.Size = new System.Drawing.Size(88, 23);
140 this.label3.TabIndex = 4;
141 this.label3.Text = "Transactional";
142 //
143 // txtpath
144 //
145 this.txtpath.Location = new System.Drawing.Point(72, 48);
146 this.txtpath.Name = "txtpath";
147 this.txtpath.Size = new System.Drawing.Size(176, 21);
148 this.txtpath.TabIndex = 3;
149 this.txtpath.Text = "Private$\\test";
150 //
151 // label2
152 //
153 this.label2.Location = new System.Drawing.Point(8, 48);
154 this.label2.Name = "label2";
155 this.label2.Size = new System.Drawing.Size(48, 23);
156 this.label2.TabIndex = 2;
157 this.label2.Text = "Path";
158 //
159 // txthost
160 //
161 this.txthost.Location = new System.Drawing.Point(72, 24);
162 this.txthost.Name = "txthost";
163 this.txthost.Size = new System.Drawing.Size(176, 21);
164
下面是一个简单的例子供参考;
1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6using MSMQ;
7namespace MyTest
8{
9 /**//// <summary>
10 /// Form2 的摘要说明。
11 /// </summary>
12 public class Form2 : System.Windows.Forms.Form
13 {
14 Forms#region Forms
15 private System.Windows.Forms.GroupBox groupBox1;
16 private System.Windows.Forms.Label label1;
17 private System.Windows.Forms.Label label2;
18 private System.Windows.Forms.Label label3;
19 private System.Windows.Forms.GroupBox groupBox2;
20 private System.Windows.Forms.TextBox txthost;
21 private System.Windows.Forms.TextBox txtpath;
22 private System.Windows.Forms.RadioButton trans1;
23 private System.Windows.Forms.RadioButton trans2;
24 private System.Windows.Forms.GroupBox groupBox3;
25 private System.Windows.Forms.Label label4;
26 private System.Windows.Forms.Button button1;
27 private System.Windows.Forms.Label label5;
28 private System.Windows.Forms.Button button2;
29 private System.Windows.Forms.TextBox txtmsg;
30 private System.Windows.Forms.TextBox txtrece;
31 /**//// <summary>
32 /// 必需的设计器变量。
33 /// </summary>
34 private System.ComponentModel.Container components = null;
35
36 public Form2()
37 {
38 //
39 // Windows 窗体设计器支持所必需的
40 //
41 InitializeComponent();
42
43 //
44 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
45 //
46 }
47
48 /**//// <summary>
49 /// 清理所有正在使用的资源。
50 /// </summary>
51 protected override void Dispose( bool disposing )
52 {
53 if( disposing )
54 {
55 if(components != null)
56 {
57 components.Dispose();
58 }
59 }
60 base.Dispose( disposing );
61 }
62 #endregion
63
64 Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
65 /**//// <summary>
66 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
67 /// 此方法的内容。
68 /// </summary>
69 private void InitializeComponent()
70 {
71 this.groupBox1 = new System.Windows.Forms.GroupBox();
72 this.groupBox2 = new System.Windows.Forms.GroupBox();
73 this.trans2 = new System.Windows.Forms.RadioButton();
74 this.trans1 = new System.Windows.Forms.RadioButton();
75 this.label3 = new System.Windows.Forms.Label();
76 this.txtpath = new System.Windows.Forms.TextBox();
77 this.label2 = new System.Windows.Forms.Label();
78 this.txthost = new System.Windows.Forms.TextBox();
79 this.label1 = new System.Windows.Forms.Label();
80 this.groupBox3 = new System.Windows.Forms.GroupBox();
81 this.button2 = new System.Windows.Forms.Button();
82 this.txtrece = new System.Windows.Forms.TextBox();
83 this.label5 = new System.Windows.Forms.Label();
84 this.button1 = new System.Windows.Forms.Button();
85 this.txtmsg = new System.Windows.Forms.TextBox();
86 this.label4 = new System.Windows.Forms.Label();
87 this.groupBox1.SuspendLayout();
88 this.groupBox2.SuspendLayout();
89 this.groupBox3.SuspendLayout();
90 this.SuspendLayout();
91 //
92 // groupBox1
93 //
94 this.groupBox1.Controls.Add(this.groupBox2);
95 this.groupBox1.Controls.Add(this.label3);
96 this.groupBox1.Controls.Add(this.txtpath);
97 this.groupBox1.Controls.Add(this.label2);
98 this.groupBox1.Controls.Add(this.txthost);
99 this.groupBox1.Controls.Add(this.label1);
100 this.groupBox1.Location = new System.Drawing.Point(8, 8);
101 this.groupBox1.Name = "groupBox1";
102 this.groupBox1.Size = new System.Drawing.Size(352, 120);
103 this.groupBox1.TabIndex = 0;
104 this.groupBox1.TabStop = false;
105 this.groupBox1.Text = "MSMQ Configuration";
106 //
107 // groupBox2
108 //
109 this.groupBox2.Controls.Add(this.trans2);
110 this.groupBox2.Controls.Add(this.trans1);
111 this.groupBox2.Location = new System.Drawing.Point(104, 72);
112 this.groupBox2.Name = "groupBox2";
113 this.groupBox2.Size = new System.Drawing.Size(144, 40);
114 this.groupBox2.TabIndex = 5;
115 this.groupBox2.TabStop = false;
116 //
117 // trans2
118 //
119 this.trans2.Checked = true;
120 this.trans2.Location = new System.Drawing.Point(72, 16);
121 this.trans2.Name = "trans2";
122 this.trans2.Size = new System.Drawing.Size(64, 19);
123 this.trans2.TabIndex = 1;
124 this.trans2.TabStop = true;
125 this.trans2.Text = "true";
126 //
127 // trans1
128 //
129 this.trans1.Location = new System.Drawing.Point(8, 16);
130 this.trans1.Name = "trans1";
131 this.trans1.Size = new System.Drawing.Size(48, 19);
132 this.trans1.TabIndex = 0;
133 this.trans1.Text = "true";
134 //
135 // label3
136 //
137 this.label3.Location = new System.Drawing.Point(8, 88);
138 this.label3.Name = "label3";
139 this.label3.Size = new System.Drawing.Size(88, 23);
140 this.label3.TabIndex = 4;
141 this.label3.Text = "Transactional";
142 //
143 // txtpath
144 //
145 this.txtpath.Location = new System.Drawing.Point(72, 48);
146 this.txtpath.Name = "txtpath";
147 this.txtpath.Size = new System.Drawing.Size(176, 21);
148 this.txtpath.TabIndex = 3;
149 this.txtpath.Text = "Private$\\test";
150 //
151 // label2
152 //
153 this.label2.Location = new System.Drawing.Point(8, 48);
154 this.label2.Name = "label2";
155 this.label2.Size = new System.Drawing.Size(48, 23);
156 this.label2.TabIndex = 2;
157 this.label2.Text = "Path";
158 //
159 // txthost
160 //
161 this.txthost.Location = new System.Drawing.Point(72, 24);
162 this.txthost.Name = "txthost";
163 this.txthost.Size = new System.Drawing.Size(176, 21);
164