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

📄 form5.cs

📁 C#写的Email邮件客户端程序skyemail.
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets; 
using System.IO; 
using System.Text;  
namespace SkyMail
{
	/// <summary>
	/// Form5 的摘要说明。
	/// </summary>
	public class Form5 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.ColumnHeader columnHeader3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form5()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form5));
			this.listView1 = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// listView1
			// 
			this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						this.columnHeader1,
																						this.columnHeader2,
																						this.columnHeader3});
			this.listView1.Location = new System.Drawing.Point(8, 8);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(400, 272);
			this.listView1.TabIndex = 1;
			this.listView1.View = System.Windows.Forms.View.Details;
			this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "名 字";
			// 
			// columnHeader2
			// 
			this.columnHeader2.Text = "邮件地址";
			// 
			// columnHeader3
			// 
			this.columnHeader3.Text = "电话";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(424, 48);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "增  加";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(424, 128);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "删  除";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(424, 208);
			this.button3.Name = "button3";
			this.button3.TabIndex = 4;
			this.button3.Text = "属   性";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// Form5
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(504, 293);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.button3,
																		  this.button2,
																		  this.button1,
																		  this.listView1});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Form5";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "地址簿";
			this.Load += new System.EventHandler(this.Form5_Load);
			this.Activated += new System.EventHandler(this.Form5_Activated);
			this.ResumeLayout(false);

		}
		#endregion

		private void Form5_Load(object sender, System.EventArgs e)
		{
			listView1.FullRowSelect=true;
			listView1.Columns[0].Width=(int)(listView1.Width*0.20); 
			listView1.Columns[1].Width=(int)(listView1.Width*0.50); 
			listView1.Columns[2].Width=(int)(listView1.Width*0.28); 
			this.DispAdd(); 
		}

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

			Form6 d=new Form6();
			d.ShowDialog();  
		}
		public void DispAdd()
		{
			string filename="address.wg";
			listView1.Items.Clear(); 
			FileInfo add=new FileInfo(filename);
			string ttemp="";
			if (add.Exists)
			{
				StreamReader addsw =new StreamReader(@filename,Encoding.GetEncoding("gb2312")) ;
				bool aerror =false;
				int n=0;
				while(!aerror) 
				{	
					string ATemp="";
					ttemp="";
					while(ATemp!=".")
					{
						ATemp = addsw.ReadLine();
						if( ATemp==null) 
						{ATemp="";aerror=true;break; }
						else
						{ttemp += ATemp+"\r\n";}
					}
					if( ttemp!="") {Aaddlist(ttemp,n); }
					n=n+1;
				}
				addsw.Close(); 
			}
			else
			{
				FileStream  Aemailstr =File.Create("skymail.wg");
				Aemailstr.Close();
			}
			
		}

		
		private string Aaddlist(string Acon,int Aid)
		{
			
			string addcon=Acon;
			int addid=Aid;
			string Aname = "";  //姓名
			string Aemail = "";    //邮件地址
			string Aphone = "";    //电话
			string Afax = "";    //fax
			string Acompany= "";       //公司
			string Aaddress = "";    //地址
			string[] heads=addcon.Split(new char[] {'\n'});
			int j=0;
			for(j=0;j<heads.Length;j++)
			{
				if (heads[j]!="")
				{
					int hint=heads[j].IndexOf(":"); ///将单行字符串以冒号为分隔分成两个字符串
					if(hint!=-1)
					{
						string headcaption;
						string headvalue;
						headcaption=heads[j].Substring(0,hint);
						headvalue=heads[j].Substring(hint+1,heads[j].Length-hint-2);
						switch (headcaption) 
						{
							case "name":
								Aname=headvalue;  
								break;
							case "email":
								Aemail=headvalue;  
								break;
							case "phone":
								Aphone=headvalue;  
								break;
							case "fax":
								Afax=headvalue; 
								break;
							case "company":///不同邮件系统存在大小写区别
								Acompany=headvalue;  
								break;
							case "address":
								Aaddress=headvalue;  
								break;
							
						}
					}	

				}
			}
			listView1.Items.Add (Aname);
			listView1.Items[addid].SubItems.Add(Aemail);
			listView1.Items[addid].SubItems.Add(Aphone);
			listView1.Items[addid].Tag=(addid); 
			return("ok");
		}

		private void Form5_Activated(object sender, System.EventArgs e)
		{
			this.DispAdd(); 
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			int i;
			for(i=0;i<listView1.SelectedItems.Count;i++)
			{
				StreamReader sr =new StreamReader(@"address.wg",Encoding.GetEncoding("gb2312")) ;
				bool error =false;
				int j=0;
				string temp="";
				while(!error) 
				{	
					string szTemp="";
					while(szTemp!=".")
					{
						szTemp = sr.ReadLine();
						if( szTemp==null) 
						{szTemp="";error=true;break; }
						else
						{
							if(j!=(int)listView1.SelectedItems[i].Tag)
							{
								temp += szTemp+"\r\n";
							}
							
						}
					}
					j=j+1;
				}
				sr.Close();  
				StreamWriter sw =new StreamWriter(@"address.wg",false,Encoding.GetEncoding("gb2312")) ;
				sw.Write(temp);
				sw.Close(); 
				this.DispAdd(); 
				
			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
						if(listView1.SelectedItems.Count==1)
						{
							Form7 d=new Form7((int)listView1.SelectedItems[0] .Tag );
							d.ShowDialog();
						}
						else
						{
							MessageBox.Show ("修改每次只能选中一个联系人");
						}
			
		}

		private void listView1_DoubleClick(object sender, System.EventArgs e)
		{
		//MessageBox.Show (listView1.SelectedItems[0].SubItems[1].Text);  
			Form4 d=new Form4();
			string temp="";
			for(int i=0;i<listView1.SelectedItems.Count;i++ )
			{
				if(i==0)
				{
					temp=listView1.SelectedItems[i].SubItems[1].Text;
				}
				else
				{
					temp=";" +temp +listView1.SelectedItems[i].SubItems[1].Text;
				}
			}
			d.Controls[7] .Text=temp;
			d.Show(); 
		}

	}
}

⌨️ 快捷键说明

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