C # Address Book--windows Form contact List

Source: Internet
Author: User

C # Address Book

Windows Form Contact List

Main Window

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewindowsformsapplication2{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Privatecontact[] Phonebook =Newcontact[1]; Private voidWrite (Contact obj) {StreamWriter SW=NewStreamWriter ("Contact.txt"); Sw. WriteLine (Phonebook.length+1); Sw. WriteLine (obj.                FirstName); Sw. WriteLine (obj.                LastName); Sw. WriteLine (obj.                Phone);  for(intx =0; x < phonebook.length; X + +) {SW. WriteLine (Phonebook[x].                    FirstName); Sw. WriteLine (Phonebook[x].                    LastName); Sw. WriteLine (Phonebook[x].                Phone); } SW.        Close (); }        Private voidRead () {StreamReader SR=NewStreamReader ("Contact.txt"); Phonebook=NewContact[convert.toint32 (Sr.                ReadLine ())];  for(intx =0; x < phonebook.length; X + +) {Phonebook[x]=NewContact (); PHONEBOOK[X]. FirstName=Sr.                    ReadLine (); PHONEBOOK[X]. LastName=Sr.                    ReadLine (); PHONEBOOK[X]. Phone=Sr.                ReadLine (); } Sr.        Close (); }        Private voidDisplay () {lstContacts.Items.Clear ();  for(intx =0; x < phonebook.length; X + +) {lstContacts.Items.Add (phonebook[x].                ToString ()); }                    }        Private voidClearForm () {Textfirstname.text=string.            Empty; Textlastname.text=string.            Empty; Textphone.text=string.        Empty; }        Private voidBtnaddcontact_click (Objectsender, EventArgs e) {Contact obj=NewContact ();            Obj._contact (Textfirstname.text,textlastname.text,textphone.text); //lstContacts.Items.Add (obj. ToString ());Bubblesort ();            Fileif ();            Write (obj);            Read ();            Display ();        ClearForm (); }        Private voidFileif () {if(File.exists ("Contact.txt"))            {                return; }Else{FileStream NewText= File.create ("Contact.txt");            Newtext.close (); }        }        Private voidForm1_Load (Objectsender, EventArgs e)            {Fileif ();            Read ();        Display (); }        Private voidBubblesort () {Contact temp; BOOLswap;  Do{Swap=false;  for(intx =0; x< (Phonebook.length-1); x + +)                {                    if(Phonebook[x].lastname.compareto (phonebook[x+1]. LastName) >0) {Temp=Phonebook[x]; PHONEBOOK[X]=phonebook[x+1]; Phonebook[x+1]=temp; Swap=true; }                }            } while(Swap = =true); }        Private voidBtnsort_click (Objectsender, EventArgs e)            {Bubblesort ();        Display (); }           }//End of Class}//End of namespace

Contact class

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacewindowsformsapplication2{classContact {//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 stringFirstName {Get{return_FirstName;} Set{_FirstName =value;} }         Public stringLastName {Get{return_lastname;} Set{_lastname =value;} }         Public stringPhone {Get{return_phone;} Set             {                if(value.) Length = = One) {_phone=value; }                Else{_phone="11111111111"; }            }        }            Public Override stringToString () {stringOutput =string.           Empty; Output+=string. Format ("{0},{1}", LastName, FirstName); Output+=string. Format (", {0} {1} {2}", Phone.substring (0,3), Phone.substring (3,4), Phone.substring (7,4)); returnoutput; }        }//End of Class}//End of namespace

Source:

Http://files.cnblogs.com/files/landv/WindowsFormContactList.zip

C # Address Book--windows Form contact List

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.