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

📄 main.cs

📁 一个利用csharp所撰写而成的手机发送sms程式
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.IO;
using System.Text;

namespace SMS
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmMain : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label lblHeading;
		private System.Windows.Forms.Label lblPackageIDLabel;
		private System.Windows.Forms.Label lblPackageID;
		private System.Windows.Forms.Label lblDelivered;
		private System.Windows.Forms.TextBox txtDelivered;
		private System.Windows.Forms.TextBox txtMessage;
		private System.Windows.Forms.Button btnDelivered;
		private System.Windows.Forms.Label lblMessage;
		private System.Windows.Forms.MainMenu mainMenu1;

		public frmMain()
		{
			InitializeComponent();
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.panel1 = new System.Windows.Forms.Panel();
			this.lblHeading = new System.Windows.Forms.Label();
			this.btnDelivered = new System.Windows.Forms.Button();
			this.lblPackageIDLabel = new System.Windows.Forms.Label();
			this.lblPackageID = new System.Windows.Forms.Label();
			this.lblDelivered = new System.Windows.Forms.Label();
			this.txtDelivered = new System.Windows.Forms.TextBox();
			this.txtMessage = new System.Windows.Forms.TextBox();
			this.lblMessage = new System.Windows.Forms.Label();
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.Color.Black;
			this.panel1.Location = new System.Drawing.Point(0, 23);
			this.panel1.Size = new System.Drawing.Size(240, 1);
			// 
			// lblHeading
			// 
			this.lblHeading.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
			this.lblHeading.Location = new System.Drawing.Point(8, 5);
			this.lblHeading.Size = new System.Drawing.Size(136, 17);
			this.lblHeading.Text = "Delivery Notification";
			// 
			// btnDelivered
			// 
			this.btnDelivered.Location = new System.Drawing.Point(144, 88);
			this.btnDelivered.Size = new System.Drawing.Size(88, 24);
			this.btnDelivered.Text = "Delivered";
			this.btnDelivered.Click += new System.EventHandler(this.btnDelivered_Click);
			// 
			// lblPackageIDLabel
			// 
			this.lblPackageIDLabel.Location = new System.Drawing.Point(8, 32);
			this.lblPackageIDLabel.Size = new System.Drawing.Size(72, 16);
			this.lblPackageIDLabel.Text = "Package ID:";
			// 
			// lblPackageID
			// 
			this.lblPackageID.Location = new System.Drawing.Point(88, 32);
			this.lblPackageID.Size = new System.Drawing.Size(144, 16);
			this.lblPackageID.Text = "345867219";
			// 
			// lblDelivered
			// 
			this.lblDelivered.Location = new System.Drawing.Point(8, 59);
			this.lblDelivered.Size = new System.Drawing.Size(72, 16);
			this.lblDelivered.Text = "Delivered:";
			// 
			// txtDelivered
			// 
			this.txtDelivered.Location = new System.Drawing.Point(88, 56);
			this.txtDelivered.Size = new System.Drawing.Size(144, 22);
			this.txtDelivered.Text = "";
			// 
			// txtMessage
			// 
			this.txtMessage.AcceptsReturn = true;
			this.txtMessage.Location = new System.Drawing.Point(8, 120);
			this.txtMessage.Multiline = true;
			this.txtMessage.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtMessage.Size = new System.Drawing.Size(224, 136);
			this.txtMessage.Text = "";
			// 
			// lblMessage
			// 
			this.lblMessage.Location = new System.Drawing.Point(8, 104);
			this.lblMessage.Size = new System.Drawing.Size(128, 16);
			this.lblMessage.Text = "Message (? chars):";
			// 
			// frmMain
			// 
			this.ClientSize = new System.Drawing.Size(258, 287);
			this.Controls.Add(this.lblMessage);
			this.Controls.Add(this.txtMessage);
			this.Controls.Add(this.txtDelivered);
			this.Controls.Add(this.lblDelivered);
			this.Controls.Add(this.lblPackageID);
			this.Controls.Add(this.lblPackageIDLabel);
			this.Controls.Add(this.btnDelivered);
			this.Controls.Add(this.lblHeading);
			this.Controls.Add(this.panel1);
			this.Menu = this.mainMenu1;
			this.MinimizeBox = false;
			this.Text = "SMS Anyplace";
			this.Load += new System.EventHandler(this.frmMain_Load);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main() 
		{
			Application.Run(new frmMain());
		}

		/// <summary>
		/// Form initialization.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void frmMain_Load(object sender, System.EventArgs e)
		{
			txtDelivered.Text = DateTime.Now.ToString();
		}

		/// <summary>
		/// Send delivery notification.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btnDelivered_Click(object sender, System.EventArgs e)
		{
			// Create XML message
			MemoryStream ms = new MemoryStream();
			XmlTextWriter xmlw = new XmlTextWriter(ms,System.Text.Encoding.UTF8);
			xmlw.WriteStartDocument();
			xmlw.WriteStartElement("Delivery");
			xmlw.WriteElementString("PackageID",lblPackageID.Text);
			xmlw.WriteElementString("Delivered",txtDelivered.Text);
			xmlw.WriteEndElement();
			xmlw.WriteEndDocument();
			xmlw.Flush();
			ms.Seek(0, SeekOrigin.Begin);
			StreamReader sr = new StreamReader(ms);
			txtMessage.Text = sr.ReadLine();
			lblMessage.Text = "Message (" + txtMessage.Text.Length.ToString() + " chars):";
			this.Refresh();
			xmlw.Close();
			sr.Close();

			// Send message
			if (0 == SMSHelper.SendSMS("+15555550123", txtMessage.Text))
				MessageBox.Show("Message sent!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
			else
				MessageBox.Show("Could not send message!", this.Text);
		}
	}
}

⌨️ 快捷键说明

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