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

📄 form8.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>
	/// Form8 的摘要说明。
	/// </summary>
	public class Form8 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.ListBox listBox2;
		private System.Windows.Forms.ListBox listBox3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form8()
		{
			//
			// 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()
		{
			this.listView1 = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.button8 = new System.Windows.Forms.Button();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.listBox2 = new System.Windows.Forms.ListBox();
			this.listBox3 = new System.Windows.Forms.ListBox();
			this.SuspendLayout();
			// 
			// listView1
			// 
			this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						this.columnHeader1,
																						this.columnHeader2});
			this.listView1.FullRowSelect = true;
			this.listView1.Location = new System.Drawing.Point(16, 24);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(136, 216);
			this.listView1.TabIndex = 0;
			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 = "邮件地址";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(232, 5);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(112, 16);
			this.label1.TabIndex = 4;
			this.label1.Text = "收件人";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(232, 85);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(100, 14);
			this.label2.TabIndex = 5;
			this.label2.Text = "抄送";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(232, 165);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 16);
			this.label3.TabIndex = 6;
			this.label3.Text = "暗送";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 5);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(96, 16);
			this.label4.TabIndex = 7;
			this.label4.Text = "地址簿";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(176, 32);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(40, 20);
			this.button1.TabIndex = 8;
			this.button1.Text = "->";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(176, 56);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(40, 20);
			this.button2.TabIndex = 9;
			this.button2.Text = "<-";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(176, 112);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(40, 20);
			this.button3.TabIndex = 10;
			this.button3.Text = "->";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(176, 136);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(40, 20);
			this.button4.TabIndex = 11;
			this.button4.Text = "<-";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// button5
			// 
			this.button5.Location = new System.Drawing.Point(176, 192);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(40, 20);
			this.button5.TabIndex = 12;
			this.button5.Text = "->";
			this.button5.Click += new System.EventHandler(this.button5_Click);
			// 
			// button6
			// 
			this.button6.Location = new System.Drawing.Point(176, 216);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(40, 20);
			this.button6.TabIndex = 13;
			this.button6.Text = "<-";
			this.button6.Click += new System.EventHandler(this.button6_Click);
			// 
			// button7
			// 
			this.button7.Location = new System.Drawing.Point(200, 256);
			this.button7.Name = "button7";
			this.button7.TabIndex = 14;
			this.button7.Text = "确定";
			this.button7.Click += new System.EventHandler(this.button7_Click);
			// 
			// button8
			// 
			this.button8.Location = new System.Drawing.Point(296, 256);
			this.button8.Name = "button8";
			this.button8.TabIndex = 15;
			this.button8.Text = "取消";
			this.button8.Click += new System.EventHandler(this.button8_Click);
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 12;
			this.listBox1.Location = new System.Drawing.Point(232, 24);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(144, 52);
			this.listBox1.TabIndex = 16;
			// 
			// listBox2
			// 
			this.listBox2.ItemHeight = 12;
			this.listBox2.Location = new System.Drawing.Point(232, 104);
			this.listBox2.Name = "listBox2";
			this.listBox2.Size = new System.Drawing.Size(144, 52);
			this.listBox2.TabIndex = 17;
			// 
			// listBox3
			// 
			this.listBox3.ItemHeight = 12;
			this.listBox3.Location = new System.Drawing.Point(232, 184);
			this.listBox3.Name = "listBox3";
			this.listBox3.Size = new System.Drawing.Size(144, 52);
			this.listBox3.TabIndex = 18;
			// 
			// Form8
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(400, 285);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.listBox3,
																		  this.listBox2,
																		  this.listBox1,
																		  this.button8,
																		  this.button7,
																		  this.button6,
																		  this.button5,
																		  this.button4,
																		  this.button3,
																		  this.button2,
																		  this.button1,
																		  this.label4,
																		  this.label3,
																		  this.label2,
																		  this.label1,
																		  this.listView1});
			this.Name = "Form8";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "选择联系人";
			this.Load += new System.EventHandler(this.Form8_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void button8_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button7_Click(object sender, System.EventArgs e)
		{
			string strto="";
			int i=0;
			for(i=0;i<listBox1.Items.Count;i++  )
			{
				if(i==0)
				{
					strto=listBox1.Items[i].ToString();
				}
				else
				{
					strto=strto+","+listBox1.Items[i].ToString();
				}
  
				
			}
			string strcc="";
			for(i=0;i<listBox2.Items.Count;i++  )
			{
				if(i==0)
				{
					strcc=listBox2.Items[i].ToString();
				}
				else
				{
					strcc=strcc+","+listBox2.Items[i].ToString();
				}
  
				
			}
			string strbc="";
			for(i=0;i<listBox3.Items.Count;i++  )
			{
				if(i==0)
				{
					strbc=listBox3.Items[i].ToString();
				}
				else
				{
					strbc=strbc+","+listBox3.Items[i].ToString();
				}
  
				
			}
			this.Owner.Controls[7].Text=strto;
			this.Owner.Controls[6].Text=strcc;
			this.Owner.Controls[0].Text=strbc;
			this.Close(); 
		}

		private void Form8_Load(object sender, System.EventArgs e)
		{
		listView1.Columns[0].Width=80;  
		listView1.Columns[1].Width=120; 
		this.DispAdd(); 
		}
		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
			{
				MessageBox.Show("您帐号的地址簿数据可能丢失!");
			}
			
		}

		
		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].Tag=(addid); 
			return("ok");
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<listView1.SelectedItems.Count;i++  )
			{
				bool fdlag=true;
				for(int j=0;j<listBox1.Items.Count;j++ )
				{
					string temp=listView1.SelectedItems[i].SubItems[1].Text;
					string temp1=listBox1.Items[j].ToString();  
					if(temp.IndexOf(temp1)!=-1) 
					{
						fdlag=false;
						
					}
				}
				if(fdlag)
				{
					listBox1.Items.Add(listView1.SelectedItems[i].SubItems[1].Text);
				}
				
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<listBox1.SelectedIndices.Count;i++  )
			{
				
				listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]) ; 
				
			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<listView1.SelectedItems.Count;i++  )
			{
				bool fdlag=true;
				for(int j=0;j<listBox2.Items.Count;j++ )
				{
					string temp=listView1.SelectedItems[i].SubItems[1].Text;
					string temp1=listBox2.Items[j].ToString();  
					if(temp.IndexOf(temp1)!=-1) 
					{
						fdlag=false;
						
					}
				}
				if(fdlag)
				{
					listBox2.Items.Add(listView1.SelectedItems[i].SubItems[1].Text);
				}
				
			}
		}

		private void button4_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<listBox2.SelectedIndices.Count;i++  )
			{
				
				listBox2.Items.RemoveAt(listBox2.SelectedIndices[i]) ; 
				
			}
		}

		private void button6_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<listBox3.SelectedIndices.Count;i++  )
			{
				
				listBox3.Items.RemoveAt(listBox3.SelectedIndices[i]) ; 
				
			}
		}

		private void button5_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<listView1.SelectedItems.Count;i++  )
			{
				bool fdlag=true;
				for(int j=0;j<listBox3.Items.Count;j++ )
				{
					string temp=listView1.SelectedItems[i].SubItems[1].Text;
					string temp1=listBox3.Items[j].ToString();  
					if(temp.IndexOf(temp1)!=-1) 
					{
						fdlag=false;
						
					}
				}
				if(fdlag)
				{
					listBox3.Items.Add(listView1.SelectedItems[i].SubItems[1].Text);
				}
				
			}
		}

		private void listView1_DoubleClick(object sender, System.EventArgs e)
		{
			if(listView1.SelectedItems.Count>0)
			{
				listBox1.Items.Add (listView1.SelectedItems[0].SubItems[1].Text);
			}
		}
	}
}

⌨️ 快捷键说明

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