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

📄 form1.cs

📁 用C#编的sms源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.cmdSend.Name = "cmdSend";
			this.cmdSend.Size = new System.Drawing.Size(76, 20);
			this.cmdSend.TabIndex = 7;
			this.cmdSend.Text = "开始发送";
			this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click);
			// 
			// chkNeedReport
			// 
			this.chkNeedReport.Location = new System.Drawing.Point(316, 116);
			this.chkNeedReport.Name = "chkNeedReport";
			this.chkNeedReport.Size = new System.Drawing.Size(76, 16);
			this.chkNeedReport.TabIndex = 6;
			this.chkNeedReport.Text = "状态报告";
			// 
			// chkChinese
			// 
			this.chkChinese.Checked = true;
			this.chkChinese.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chkChinese.Location = new System.Drawing.Point(236, 116);
			this.chkChinese.Name = "chkChinese";
			this.chkChinese.Size = new System.Drawing.Size(80, 16);
			this.chkChinese.TabIndex = 5;
			this.chkChinese.Text = "中文短信";
			// 
			// txtMsg
			// 
			this.txtMsg.Location = new System.Drawing.Point(228, 36);
			this.txtMsg.Multiline = true;
			this.txtMsg.Name = "txtMsg";
			this.txtMsg.Size = new System.Drawing.Size(256, 76);
			this.txtMsg.TabIndex = 4;
			this.txtMsg.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(236, 12);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(72, 20);
			this.label6.TabIndex = 3;
			this.label6.Text = "短信内容";
			// 
			// lstMobileNo
			// 
			this.lstMobileNo.ItemHeight = 12;
			this.lstMobileNo.Location = new System.Drawing.Point(16, 36);
			this.lstMobileNo.Name = "lstMobileNo";
			this.lstMobileNo.Size = new System.Drawing.Size(200, 76);
			this.lstMobileNo.TabIndex = 2;
			// 
			// txtMobileNo
			// 
			this.txtMobileNo.Location = new System.Drawing.Point(88, 12);
			this.txtMobileNo.Name = "txtMobileNo";
			this.txtMobileNo.Size = new System.Drawing.Size(128, 21);
			this.txtMobileNo.TabIndex = 1;
			this.txtMobileNo.Text = "";
			this.txtMobileNo.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtMobileNo_KeyPress);
			this.txtMobileNo.TextChanged += new System.EventHandler(this.txtMobileNo_TextChanged);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(28, 16);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(56, 12);
			this.label5.TabIndex = 0;
			this.label5.Text = "手机号码";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.txtInfo);
			this.groupBox3.Location = new System.Drawing.Point(0, 220);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(496, 164);
			this.groupBox3.TabIndex = 2;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "提示信息";
			// 
			// txtInfo
			// 
			this.txtInfo.Location = new System.Drawing.Point(12, 28);
			this.txtInfo.Multiline = true;
			this.txtInfo.Name = "txtInfo";
			this.txtInfo.Size = new System.Drawing.Size(472, 128);
			this.txtInfo.TabIndex = 0;
			this.txtInfo.Text = "";
			// 
			// TimerSend
			// 
			this.TimerSend.Tick += new System.EventHandler(this.TimerSend_Tick);
			// 
			// axSMS
			// 
			this.axSMS.Enabled = true;
			this.axSMS.Location = new System.Drawing.Point(12, 388);
			this.axSMS.Name = "axSMS";
			this.axSMS.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axSMS.OcxState")));
			this.axSMS.Size = new System.Drawing.Size(33, 33);
			this.axSMS.TabIndex = 4;
			this.axSMS.SendComplete += new AxTransoftSMSControl30.__SMS_SendCompleteEventHandler(this.axSMS_SendComplete);
			this.axSMS.MsgReceived += new AxTransoftSMSControl30.__SMS_MsgReceivedEventHandler(this.axSMS_MsgReceived);
			this.axSMS.Error += new AxTransoftSMSControl30.__SMS_ErrorEventHandler(this.axSMS_Error);
			this.axSMS.ReportReceived += new AxTransoftSMSControl30.__SMS_ReportReceivedEventHandler(this.axSMS_ReportReceived);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(496, 417);
			this.Controls.Add(this.axSMS);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Name = "Form1";
			this.Text = "C# 短信测试程序";
			this.Load += new System.EventHandler(this.frmMain_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.axSMS)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void frmMain_Load(object sender, System.EventArgs e)
		{
			cboMobileType.Text =  "Wavecom模块";
			cboRate.Text = "9600,n,8,1";
			cboSMSPort.Text = "1";
		}

		private void cmdConnect_Click(object sender, System.EventArgs e)
		{

			if (cboMobileType.Text == "标准手机")
			{
				axSMS.MobileType = 0;
			}

			if (cboMobileType.Text == "Wavecom模块")
			{
				axSMS.MobileType = 1;
			}

			if (cboMobileType.Text == "Nokia手机")
			{
				axSMS.MobileType = 2;
			}

			if (cboMobileType.Text == "西门子手机")
			{
				axSMS.MobileType = 3;
			}
		
			axSMS.CommPort = short.Parse(cboSMSPort.Text) ; 
			axSMS.CenterNo = txtCenterNo.Text ;
			axSMS.Settings = cboRate.Text ;
		

			if (axSMS.CommOpen() == 0)
			{
				MessageBox.Show ("连接成功!");
			}
			else
			{
				MessageBox.Show ("连接失败!");
			}
		}

		private void cmdDisConnect_Click(object sender, System.EventArgs e)
		{
			axSMS.CommClose() ;
			MessageBox.Show ("断开成功!");
		}

		private void txtMobileNo_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void cmdSend_Click(object sender, System.EventArgs e)
		{
			TimerSend.Enabled =true; 
		}

		private void TimerSend_Tick(object sender, System.EventArgs e)
		{
			
			//  这里是发送短信的核心代码,
			// 注:定时触发一次,一定是只发送一条短信
			//    发送之前判断控件状态是否忙
			
			if (lstMobileNo.Items.Count >0 )
			{
				//    发送之前判断控件状态是否忙
				if( axSMS.IsBusy == false ){
				   axSMS.SendMsg(lstMobileNo.Items[0].ToString(),txtMsg.Text,true,false,false); 
				}
			}
		}

		private void txtMobileNo_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (e.KeyChar == 13){
				lstMobileNo.Items.Add(txtMobileNo.Text ); 
				txtMobileNo.Text="";
			}
		}

		private void axSMS_SendComplete(object sender, AxTransoftSMSControl30.__SMS_SendCompleteEvent e)
		{

			txtInfo.Text = txtInfo.Text + "发送给"  + lstMobileNo.Items[0].ToString() + "成功" +"\r\n" ;
			if (lstMobileNo.Items.Count >0){
				lstMobileNo.Items.RemoveAt(0); 
			}
		}

		private void axSMS_Error(object sender, AxTransoftSMSControl30.__SMS_ErrorEvent e)
		{
			txtInfo.Text = txtInfo.Text + "发送给"  + lstMobileNo.Items[0].ToString() + "失败" + "\r\n" ;
			if (lstMobileNo.Items.Count >0)
			{
				lstMobileNo.Items.RemoveAt(0); 
			}
		
		}

		private void axSMS_MsgReceived(object sender, AxTransoftSMSControl30.__SMS_MsgReceivedEvent e)
		{
		
			txtInfo.Text = txtInfo.Text + "接收短信从"  + e.msgSender.ToString() + "内容:" + e.msg.ToString() + "\r\n" ;
		}

		private void axSMS_ReportReceived(object sender, AxTransoftSMSControl30.__SMS_ReportReceivedEvent e)
		{
			txtInfo.Text = txtInfo.Text + "接收状态报告从"   +  e.receiver.ToString() + "\r\n" ;
		}
		
	}
}

⌨️ 快捷键说明

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