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的更多相关文章

  1. 如何用Web技术开发Windows Form应用

    现在H5很热,很多互联网公司的产品都采用混合编程,其中各个平台客户端的“壳”为原生控件,但是内容很多都是Web网页,因此可以做出很多炫酷的效果.随着Node.js和Ionic等框架的出现,现在感觉Ja ...

  2. Windows Form 中快捷键设置

    在Windows Form程序中使用带下划线的快捷键只需要进行设置: 就能够工作.

  3. VS2008 Windows Form项目安装包生成详解

    2008 Windows Form项目的发布对有经验的程序员来说,可能不值一提,但对很多新手来说却不知道如何操作,因为在很多关于Visual Studio的书籍中也没有相关介绍,权威如<C# 2 ...

  4. VISUAL STUDIO 2008 WINDOWS FORM项目发布生成安装包详解(转)

    转自:http://www.cnblogs.com/killerofyang/archive/2012/05/31/2529193.html Visual Studio 2008 Windows Fo ...

  5. 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 ...

  6. windows form (窗体) 之间传值小结

    windows form (窗体) 之间传值小结   windows form (窗体) 之间传值小结 在windows form之间传值,我总结了有四个方法:全局变量.属性.窗体构造函数和deleg ...

  7. Ninject之旅之十二:Ninject在Windows Form程序上的应用(附程序下载)

    摘要: 下面的几篇文章介绍如何使用Ninject创建不同类型的应用系统.包括: Windows Form应用系统 ASP.NET MVC应用系统 ASP.NET Web Form应用系统 尽管对于不同 ...

  8. Windows Form线程同步

    .Net多线程开发中,经常需要启动工作线程Worker thread处理某些事情,而工作线程中又需要更新主线程UI thread的界面状态.我们只能在主线程中操作界面控件,否则.Net会抛出异常. 那 ...

  9. 在WPF中添加Windows Form控件(包括 ocx控件)

      首先,需要向项目中的reference添加两个dll,一个是.NET库中的System.Windows.Forms,另外一个是WindowsFormsIntegration,它的位置一般是在C:\ ...

随机推荐

  1. Python open() 函数

    open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=T) 模式 描述 r 以只读方 ...

  2. 最简单的HashMap底层原理介绍

    HashMap 底层原理  1.HashMap底层概述 2.JDK1.7实现方式 3.JDK1.8实现方式 4.关键名词 5.相关问题 1.HashMap底层概述 在JDK1.7中HashMap采用的 ...

  3. Go语言中的map

    map是一个集合,可以使用类似处理数组和切片的方式迭代map中的元素.但map是无序的集合.无序的原因是map的实现使用了散列表. map的创建并初始化主要是两种方式: 1.内置的make函数 2.使 ...

  4. 手动注册 Omron SYSMAC OPC Server 2

    使用如下注册表操作实现 Omron SYSMAC OPC Server 2 的注册,包括COM组件和ProgID. 注意,手动注册适用于在win10等不兼容老版本程序的正常使用的情况,此方法一般在单机 ...

  5. sqlserver 2012 分页

    --2012的OFFSET分页方式 select number from spt_values where type='p' order by number offset 10 rows fetch ...

  6. FFmpeg configure: rename cuda to ffnvcodec 2018-03-06

    FFmpeg version of headers required to interface with Nvidias codec APIs. Corresponds to Video Codec ...

  7. $Djangon admin界面 添加表 增删查改

    from django.contrib import admin表变中文 class Meta: verbose_name_plural='评论表' null=True的字段:admin创建要求写可以 ...

  8. 简单的三级联动demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  9. 缺失dll的问题

    不小心运行一下什么程序就会出现缺失xxx.dll的问题,太烦了,遇到好多,一直没有记录.现在开始记录,以便日后查看~ 1. api-ms-win-crt-runtime-l1-1-0.dll 64位系 ...

  10. Confluence 6 审查日志的对象

    审查日志记录一下事件的信息,这个记录不是详细的信息列表.但是这些信息能够让你了解你能够在日志中看到些什么内容. 空间 创建和删除一个空间. 编辑空间细节,主题,配色方案或者样式表. 修改空间权限,包括 ...