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:\ ...
随机推荐
- STL 智能指针
转自: https://blog.csdn.net/k346k346/article/details/81478223 STL一共给我们提供了四种智能指针:auto_ptr.unique_ptr.sh ...
- UVA1194 Machine Schedule
题目地址:UVA1194 Machine Schedule 二分图最小覆盖模型的要素 每条边有两个端点,二者至少选择一个.简称 \(2\) 要素. \(2\) 要素在本题中的体现 每个任务要么在 \( ...
- MII与RMII接口的区别【转】
转自:https://blog.csdn.net/fun_tion/article/details/70270632 1.概述 MII即“媒体独立接口”,也叫“独立于介质的接口”.它是IEEE-802 ...
- Windows PowerShell 入門(1)-基本操作編
Microsoftが提供している新しいシェル.Windows Power Shellの基本操作方法を学びます.インストール.起動終了方法.コマンドレット.命名規則.エイリアス.操作方法の調べ方について ...
- Memcached技术
Memcached技术 介绍: memcached是一种缓存技术, 他可以把你的数据放入内存,从而通过内存访问提速,因为内存最快的, memcached技术的主要目的提速, 在memachec 中维护 ...
- python获取windows信息
转载自http://www.blog.pythonlibrary.org/2010/02/06/more-windows-system-information-with-python/ How to ...
- centos系统初始化配置
.改主机名: sed -i 's#HOSTNAME=.*#HOSTNAME=u05mix06.yaya.corp#g' /etc/sysconfig/network && hostna ...
- django-form介绍
Django form表单 目录 普通方式手写注册功能 views.py login.html 使用form组件实现注册功能 views.py login2.html 常用字段与插件 initia ...
- JS调用摄像头并上传图片到服务器
本功能只能把图片转成base64码上传,如何上传图片还没有修改出来,有兴趣的朋友弄出来了,请给我留下言,谢谢了! 直接上代码,需要的朋友直接复制就可以使用了. <!DOCTYPE html> ...
- bootstrap栅格系统中同行div高度不一致的解决方法
通过div底部的margin和padding实现,缺点:下边框无法完整显示,建议在无边框情况下使用 .row{ overflow: hidden; } [class*="col-" ...