?? form1.cs
字號:
this.Button5,
this.Label7,
this.jsnr,
this.Label6});
this.GroupBox3.Location = new System.Drawing.Point(16, 376);
this.GroupBox3.Name = "GroupBox3";
this.GroupBox3.Size = new System.Drawing.Size(592, 128);
this.GroupBox3.TabIndex = 7;
this.GroupBox3.TabStop = false;
this.GroupBox3.Text = "接收短信測試";
//
// Button5
//
this.Button5.Location = new System.Drawing.Point(504, 24);
this.Button5.Name = "Button5";
this.Button5.TabIndex = 8;
this.Button5.Text = "接收短信";
this.Button5.Click += new System.EventHandler(this.Button5_Click);
//
// Label7
//
this.Label7.BackColor = System.Drawing.Color.AliceBlue;
this.Label7.ForeColor = System.Drawing.Color.Black;
this.Label7.Location = new System.Drawing.Point(40, 104);
this.Label7.Name = "Label7";
this.Label7.Size = new System.Drawing.Size(448, 16);
this.Label7.TabIndex = 7;
this.Label7.Text = "*接收短信息返回字符串格式為:手機號碼|短信內容||手機號碼|短信內容||";
//
// jsnr
//
this.jsnr.Location = new System.Drawing.Point(112, 24);
this.jsnr.Multiline = true;
this.jsnr.Name = "jsnr";
this.jsnr.Size = new System.Drawing.Size(376, 72);
this.jsnr.TabIndex = 1;
this.jsnr.Text = "";
//
// Label6
//
this.Label6.Location = new System.Drawing.Point(32, 24);
this.Label6.Name = "Label6";
this.Label6.Size = new System.Drawing.Size(72, 23);
this.Label6.TabIndex = 0;
this.Label6.Text = "接收內容:";
//
// Button4
//
this.Button4.Location = new System.Drawing.Point(280, 512);
this.Button4.Name = "Button4";
this.Button4.TabIndex = 6;
this.Button4.Text = "退出";
this.Button4.Click += new System.EventHandler(this.Button4_Click);
//
// GroupBox2
//
this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.Label12,
this.Button3,
this.fsnr,
this.jshm,
this.Label5,
this.Label4});
this.GroupBox2.Location = new System.Drawing.Point(16, 224);
this.GroupBox2.Name = "GroupBox2";
this.GroupBox2.Size = new System.Drawing.Size(592, 144);
this.GroupBox2.TabIndex = 5;
this.GroupBox2.TabStop = false;
this.GroupBox2.Text = "發送短信測試";
//
// Button3
//
this.Button3.Location = new System.Drawing.Point(504, 24);
this.Button3.Name = "Button3";
this.Button3.TabIndex = 5;
this.Button3.Text = "發送短信";
this.Button3.Click += new System.EventHandler(this.Button3_Click);
//
// fsnr
//
this.fsnr.Location = new System.Drawing.Point(112, 56);
this.fsnr.Multiline = true;
this.fsnr.Name = "fsnr";
this.fsnr.Size = new System.Drawing.Size(376, 56);
this.fsnr.TabIndex = 3;
this.fsnr.Text = "";
//
// jshm
//
this.jshm.Location = new System.Drawing.Point(112, 24);
this.jshm.Name = "jshm";
this.jshm.Size = new System.Drawing.Size(376, 21);
this.jshm.TabIndex = 2;
this.jshm.Text = "";
//
// Label5
//
this.Label5.Location = new System.Drawing.Point(32, 56);
this.Label5.Name = "Label5";
this.Label5.Size = new System.Drawing.Size(72, 32);
this.Label5.TabIndex = 1;
this.Label5.Text = "發送內容:";
//
// Label4
//
this.Label4.Location = new System.Drawing.Point(32, 32);
this.Label4.Name = "Label4";
this.Label4.Size = new System.Drawing.Size(72, 24);
this.Label4.TabIndex = 0;
this.Label4.Text = "接收號碼:";
//
// Label1
//
this.Label1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.Label1.BackColor = System.Drawing.Color.LightSteelBlue;
this.Label1.Font = new System.Drawing.Font("方正姚體", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Label1.Location = new System.Drawing.Point(16, 8);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(592, 40);
this.Label1.TabIndex = 8;
this.Label1.Text = "短信接口C#測試";
this.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// Label12
//
this.Label12.BackColor = System.Drawing.Color.AliceBlue;
this.Label12.Location = new System.Drawing.Point(32, 120);
this.Label12.Name = "Label12";
this.Label12.Size = new System.Drawing.Size(456, 16);
this.Label12.TabIndex = 7;
this.Label12.Text = "小靈通格式:本地:106+區號+號碼;外地:106+0+區號+號碼";
//
// TestGSM
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(624, 541);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.Label1,
this.GroupBox3,
this.Button4,
this.GroupBox2,
this.GroupBox1});
this.Name = "TestGSM";
this.Text = "Form1";
this.GroupBox1.ResumeLayout(false);
this.GroupBox3.ResumeLayout(false);
this.GroupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new TestGSM());
}
private void Button1_Click(object sender, System.EventArgs e)
{
jqhm.Text = GSMModem.GSMModemGetSnInfoNew(Device.Text,Baud.Text);
Device.Text = GSMModem.GSMModemGetDevice();
Baud.Text = GSMModem.GSMModemGetBaudrate();
cwxx.Text = GSMModem.GSMModemGetErrorMsg();
}
private void Button5_Click(object sender, System.EventArgs e)
{
//1)連接設備
if(GSMModem.GSMModemInitNew(Device.Text, Baud.Text, null, null, false, sqhm.Text) ==true)
MessageBox.Show("GSMModemInit: 連接成功!", "提示", MessageBoxButtons.OK);
else
{
MessageBox.Show("GSMModemInit: 連接失敗!" + GSMModem.GSMModemGetErrorMsg(), "提示", MessageBoxButtons.OK);
return;
}
Device.Text = GSMModem.GSMModemGetDevice();
Baud.Text = GSMModem.GSMModemGetBaudrate();
cwxx.Text = GSMModem.GSMModemGetErrorMsg();
//2)接收短信
jsnr.Text = GSMModem.GSMModemSMSReadAll(0);
cwxx.Text = GSMModem.GSMModemGetErrorMsg();
//3) 顯示錯誤信息
cwxx.Text = GSMModem.GSMModemGetErrorMsg();
}
private void Button4_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void Button3_Click(object sender, System.EventArgs e)
{
int smslen;
//0) 格式檢查
if(jshm.Text == "")
{
MessageBox.Show("手機號碼不能為空!","提示", MessageBoxButtons.OK);
jshm.Focus();
return;
}
smslen = jshm.Text.Length;
//if(smslen != 11)
//{
// MessageBox.Show("手機號碼長度不對!", "提示", MessageBoxButtons.OK);
// jshm.Focus();
// return;
//}
if(fsnr.Text == "")
{
MessageBox.Show("短信內容不能為空!", "提示", MessageBoxButtons.OK);
fsnr.Focus();
return;
}
//1)連接設備
if(GSMModem.GSMModemInitNew(Device.Text, Baud.Text, null, null, false, sqhm.Text)==true)
MessageBox.Show("GSMModemInit: 連接成功!","提示", MessageBoxButtons.OK);
else
{
MessageBox.Show("GSMModemInit: 連接失敗!" + GSMModem.GSMModemGetErrorMsg(),"提示", MessageBoxButtons.OK);
return;
}
Device.Text = GSMModem.GSMModemGetDevice();
Baud.Text = GSMModem.GSMModemGetBaudrate();
cwxx.Text =GSMModem.GSMModemGetErrorMsg();
//2) 發送短信
smslen = System.Text.Encoding.Default.GetByteCount(fsnr.Text);
if(GSMModem.GSMModemSMSsend(null, 8, fsnr.Text, smslen, jshm.Text, false) == true)
MessageBox.Show("GSMModemSMSsend: 短信發送成功!", "提示", MessageBoxButtons.OK);
else
MessageBox.Show("GSMModemSMSsend: 短信發送失敗!" + GSMModem.GSMModemGetErrorMsg(), "提示", MessageBoxButtons.OK);
//3) 顯示錯誤信息
cwxx.Text =GSMModem.GSMModemGetErrorMsg();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -