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:\ ...
随机推荐
- Linux下查询文件的md5,sha1值
验证下载下来的文件包是不是一致 ··· 验证md5值 #md5sum filename 验证shal值 #sha1sum filename ···
- SHA1算法原理【转】
转自:https://www.cnblogs.com/scu-cjx/p/6878853.html 一.SHA1与MD5差异 SHA1对任意长度明文的预处理和MD5的过程是一样的,即预处理完后的明文长 ...
- oracle 多行变一行 wmsys.wm_concat
背景 还是那个问题,部分程序员喜欢用sql解决问题.发现了这个函数,当初真是大喜过望,现在是哭笑不得.10g支持这个函数,11好像不支持了,而且只有oracle支持,其实自己写个通用方法 ...
- Excel 2013 表格自用技巧
参考 Excel表格的基本操作(精选36个技巧) Excel2013基本用法 关于VLOOKUP函数 目录 快速复制单元格 单元格内强制换行 锁定标题行 查找重复值 万元显示 单元格中显示001 按月 ...
- deque-->collections之#双向消息队列
deque 双向队列单项队列 方法: append #往右边添加一个appendleft #左边添加clear #清空队列count #看看这个队列里某个元素出现了多少次extend #从右边多个元素 ...
- E: The package code needs to be reinstalled, but I can't find an archive for it.
ubuntu安装软件时报错: E: The package code needs to be reinstalled, but I can't find an archive for it. 解决方法 ...
- web@css高级选择器(after,befor用法),基本css样式
1.高阶选择器:子代后代,相邻通用兄弟,交集并集,属性,伪类,伪元素子代后代选择器 div>p{} div p{}相邻通用兄弟 div+p{} div~p{}理解:div同学的同桌p di ...
- vue与jquery合作
2017年2月26日 14:59:34 星期日 场景: jquery的$.post, $.get是$.ajax的封装, 是异步的 因此, 有肯能在初始化vue实例的时候, 异步请求的结果还没返回, 这 ...
- oracle 报表带小计合计
selectcase when (grouping(glbm)=1) then '合计' else DECODE(glbm,null,'',glbm) end glbm,case when (grou ...
- bootstrap栅格系统中同行div高度不一致的解决方法
通过div底部的margin和padding实现,缺点:下边框无法完整显示,建议在无边框情况下使用 .row{ overflow: hidden; } [class*="col-" ...