C#通讯录——Windows Form Contact List
C#通讯录
Windows Form Contact List

主窗口
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Contact[] phoneBook = new Contact[];
private void Write(Contact obj)
{ StreamWriter sw = new StreamWriter("contact.txt");
sw.WriteLine(phoneBook.Length + );
sw.WriteLine(obj.FirstName);
sw.WriteLine(obj.LastName);
sw.WriteLine(obj.Phone); for (int x = ; x < phoneBook.Length; x++)
{
sw.WriteLine(phoneBook[x].FirstName);
sw.WriteLine(phoneBook[x].LastName);
sw.WriteLine(phoneBook[x].Phone);
}
sw.Close(); }
private void Read()
{ StreamReader sr = new StreamReader("contact.txt");
phoneBook = new Contact[Convert.ToInt32(sr.ReadLine())]; for (int x = ; x < phoneBook.Length; x++)
{
phoneBook[x] = new Contact();
phoneBook[x].FirstName = sr.ReadLine();
phoneBook[x].LastName = sr.ReadLine();
phoneBook[x].Phone = sr.ReadLine();
}
sr.Close(); }
private void Display()
{ lstContacts.Items.Clear();
for (int x = ; x < phoneBook.Length; x++)
{
lstContacts.Items.Add(phoneBook[x].ToString());
} }
private void ClearForm()
{
textFirstName.Text = string.Empty;
textLastName.Text = string.Empty;
textPhone.Text = string.Empty; }
private void btnAddContact_Click(object sender, EventArgs e)
{
Contact obj = new Contact();
obj._Contact(textFirstName.Text,textLastName.Text,textPhone.Text); //lstContacts.Items.Add(obj.ToString());
BubbleSort();
FileIf();
Write(obj);
Read();
Display();
ClearForm(); }
private void FileIf()
{
if (File.Exists("contact.txt"))
{
return;
}else
{
FileStream NewText = File.Create("contact.txt");
NewText.Close();
} }
private void Form1_Load(object sender, EventArgs e)
{
FileIf();
Read();
Display();
}
private void BubbleSort()
{
Contact temp;
bool swap;
do
{
swap = false;
for(int x = ; x<(phoneBook.Length -);x++)
{
if (phoneBook[x].LastName.CompareTo(phoneBook[x+].LastName)>){
temp = phoneBook[x];
phoneBook[x]=phoneBook[x+];
phoneBook[x+]=temp;
swap =true;
}
}
}while(swap == true);
} private void btnSort_Click(object sender, EventArgs e)
{
BubbleSort();
Display();
} }//end of class
}//end of namespace
Contact类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace WindowsFormsApplication2
{ class Contact
{ //public Contact()
//{
// FirstName = "landv";
// LastName = "li";
// Phone = "13903120312"; //}
//public Contact(string _FirstName, string _LastName, string _Phone)
//{
// FirstName = _FirstName;
// LastName = _LastName;
// Phone = _Phone;
//} public void _Contact(string _FirstName, string _LastName, string _Phone)
{
FirstName = _FirstName;
LastName = _LastName;
Phone = _Phone;
} private string _FirstName;
private string _LastName;
private string _Phone; public string FirstName
{
get { return _FirstName; }
set { _FirstName = value; }
}
public string LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public string Phone
{
get { return _Phone; }
set
{
if(value.Length == )
{
_Phone = value;
}
else
{
_Phone = "";
}
}
} public override string ToString()
{
string output = string.Empty;
output += string.Format("{0},{1}", LastName, FirstName);
output += string.Format(",{0} {1} {2}", Phone.Substring(, ), Phone.Substring(, ), Phone.Substring(, ));
return output; } }// end of class
}//end of namespace
源码下载地址:
http://files.cnblogs.com/files/landv/WindowsFormContactList.zip
C#通讯录——Windows Form Contact List的更多相关文章
- 如何用Web技术开发Windows Form应用
现在H5很热,很多互联网公司的产品都采用混合编程,其中各个平台客户端的“壳”为原生控件,但是内容很多都是Web网页,因此可以做出很多炫酷的效果.随着Node.js和Ionic等框架的出现,现在感觉Ja ...
- Windows Form 中快捷键设置
在Windows Form程序中使用带下划线的快捷键只需要进行设置: 就能够工作.
- VS2008 Windows Form项目安装包生成详解
2008 Windows Form项目的发布对有经验的程序员来说,可能不值一提,但对很多新手来说却不知道如何操作,因为在很多关于Visual Studio的书籍中也没有相关介绍,权威如<C# 2 ...
- VISUAL STUDIO 2008 WINDOWS FORM项目发布生成安装包详解(转)
转自:http://www.cnblogs.com/killerofyang/archive/2012/05/31/2529193.html Visual Studio 2008 Windows Fo ...
- C# Adding Hyperlink to Windows Form z
When creating a Windows form in C#, we would like to create a hyperlink so that when the user click ...
- windows form (窗体) 之间传值小结
windows form (窗体) 之间传值小结 windows form (窗体) 之间传值小结 在windows form之间传值,我总结了有四个方法:全局变量.属性.窗体构造函数和deleg ...
- Ninject之旅之十二:Ninject在Windows Form程序上的应用(附程序下载)
摘要: 下面的几篇文章介绍如何使用Ninject创建不同类型的应用系统.包括: Windows Form应用系统 ASP.NET MVC应用系统 ASP.NET Web Form应用系统 尽管对于不同 ...
- Windows Form线程同步
.Net多线程开发中,经常需要启动工作线程Worker thread处理某些事情,而工作线程中又需要更新主线程UI thread的界面状态.我们只能在主线程中操作界面控件,否则.Net会抛出异常. 那 ...
- 在WPF中添加Windows Form控件(包括 ocx控件)
首先,需要向项目中的reference添加两个dll,一个是.NET库中的System.Windows.Forms,另外一个是WindowsFormsIntegration,它的位置一般是在C:\ ...
随机推荐
- 在 C# 中,(int) ,Int32.Parse() 和 Convert.toInt32() 三种方法的区别
在 C# 中,(int),Int32.Parse() 和 Convert.toInt32() 三种方法有何区别? int 关键字表示一种整型,是32位的,它的 .NET Framework 类型为 S ...
- sqlserver 导出数据
背景 一看到这个标题,还有这个内容,感觉当初记录这个知识点真是记录的太简单了.不过通过这个知识点我还真想起了当初的一些事情.写的题外话可能更有意思,希望每篇文章我都能加个当时的题外记录.当时一直搞or ...
- Uncaught RangeError: Maximum call stack size exceeded
环境: jquery+bootstrap+bootstrapValidator 问题描述:有个form表单,一点击按钮提交,就会报如题错误.正常应该是去校验表单输入. 解决: 从日志分析来看,报错的起 ...
- mac 上如何安装非app store上的下载的软件-------打开未知来源
打开了 Terminal 终端后 ,在命令提示后输入 sudo spctl --master-disable 并按下回车执行,如下图所示. 随后再输入当前 Mac 用户的密码,如下图所示. 如 ...
- Ex 2_4 假定您需要在以下三种算法中作出抉择..._第三次作业
- [MySQL]group by 与 having 结合函数 的统计技巧
group by 与 having 允许字段使用函数,根据函数运行的结果group by分组或having设置选择条件; 同时group by 与 having 也允许使用字段别名 示例表a: id ...
- GDOI2018 滑稽子图 [斯特林数,树形DP]
传送门并没有 思路 见到那么小的\(k\)次方,又一次想到斯特林数. \[ ans=\sum_{T} f(T)^k = \sum_{i=0}^k i!S(k,i)\sum_{T} {f(T)\choo ...
- Java常见runtime exception
ArithmeticException,:算数异常ArrayStoreException,数组存储异常BufferOverflowException,编码出错异常 解决方法: 使用Eclipse开发一 ...
- InstallUtil操作WindowsService
要安装windows service 首先要找到 InstallUtil.exe,InstallUtil.exe位置在 C:\Windows\Microsoft.NET\Framework\v4.0. ...
- Linux永久修改IP地址
通常我们为了快速修改IP地址,会这么做 ifconfig eth0 192.168.0.2 netmask 255.255.255.0 这样修改IP地址后,你再运行ifconfig命令后,的确IP地址 ...