Question

In: Computer Science

Must be in C#: 7. E-MAIL ADDRESS BOOK Create a Windows Forms Application with a class...

Must be in C#: 7. E-MAIL ADDRESS BOOK Create a Windows Forms Application with a class named PersonEntry. The PersonEntry class should have properties for a person’s name, e-mail address, and phone number. Also, create a text file that contains the names, e-mail addresses, and phone numbers for at least five people. When the application starts, it should read the data from the file and create a PersonEntry object for each person’s data. The PersonEntry objects should be added to a List, and each person’s name should be displayed in a list box on the application’s main form. When the user selects a name from the list box, a second form should appear displaying that person’s name, e-mail address, and phone number. There are additional requirements; please see Main Differences between the Textbook Instructions and This Document above.

Solutions

Expert Solution

SourceCode:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace PhoneBook

{

    public partial class Form1 : Form

    {

        //create a List object of PersonEntry type

        List<PersonEntry> entries = new List<PersonEntry>();

        public Form1()

        {

            InitializeComponent();

        }

        //create a class called PersonEntry

        class PersonEntry

        {

            //declare the required class variables

            public string name;

            public string email;

            public string phone_num;

            //define the constructor of the class

            public PersonEntry()

            {

                name = "";

                email = "";

                phone_num = "";

            }

            //setter methods

            public void setName(string pname)

            {

                name = pname;

            }

            public void setEmail(string pemail)

            {

                email = pemail;

            }

            public void setPhone(string phone)

            {

                phone_num = phone;

            }

            //getter methods

            public string getName()

            {

                return name;

            }

            public string getEmail()

            {

                return email;

            }

            public string getPhone()

            {

                return phone_num;

            }

        }

        //when the create list button is click the following

        //is done

        private void listbtn_Click(object sender, EventArgs e)

        {

            //declare a string variable and a delimiter

            string line;

            char delimiter = '\t';

            //create an object to StreamReader

            StreamReader readfile = new StreamReader(@"C:\Users\soujanya.m\Documents\Visual Studio 2010\Projects\PhoneBook\PhoneBook\PhoneBook.txt");

            //loop until end of stream

            while (!readfile.EndOfStream)

            {

                //read each line from the file

                line = readfile.ReadLine();

                //split the line at give delimiter

                string[] parse = line.Split(delimiter);

                //create an object to the PersonEntry class

                PersonEntry perEntry = new PersonEntry();

                //set the values

                perEntry.setName(parse[0]);

                perEntry.setEmail(parse[1]);

                perEntry.setPhone(parse[2]);

                //add the object to the list called entries

                entries.Add(perEntry);

                //add the names to the list box

                listBox1.Items.Add(perEntry.getName());

            }

        }

        //logic to close the form on clicking the exit button

        private void exitbtn_Click(object sender, EventArgs e)

        {

            Close();

        }

        //when the items are selected, a new form will be opened

        //and displays the respective details of the name selected

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

        {

            Form newform = new Form();

            int index = listBox1.SelectedIndex;

            newform.Text = entries[index].getName() + " details: ";

            string str = "";

            Label lb = new Label();

            //add the string values to display

            str += "Name: " + entries[index].getName() + "\n";

            str += "Email address: " + entries[index].getEmail() + "\n";

            str += "Phone number: " + entries[index].getPhone() + "\n";

            //set the size and font of the label

            lb.Font = new Font("Serif", 12, FontStyle.Bold);

            lb.Size = new System.Drawing.Size(250, 250);

            //add the string to the label

            lb.Text = str;

            lb.Visible = true;

            lb.Location = new System.Drawing.Point(10, 10);

            //add the label to the newform

            newform.Controls.Add(lb);

            //set the size of the new form

            newform.Size = new System.Drawing.Size(300, 200);

            newform.ShowDialog();

        }

    }

}

Sample Input and Output:


Related Solutions

Must be in Visual C# using windows forms : Create an application that opens a specified...
Must be in Visual C# using windows forms : Create an application that opens a specified text file and then displays a list of all the unique words found in the file. Hint: Use a LINQ method to remove all duplicate words.
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
Windows Forms application using Visual Basic: Create a class called Character that a role-playing game might...
Windows Forms application using Visual Basic: Create a class called Character that a role-playing game might use to represent a character within the game. A character should include six stats as instance variables – strength, dexterity, constitution, intelligence, wisdom and charisma (all types are int). Your class should have a constructor that initializes these six instance variables. Provide Properties with an appropriate set and get block for each instance variable. In addition, provide a method named getStatsTotal that calculates the...
C# windows application form. Create a base class to store characteristics about a loan. Include customer...
C# windows application form. Create a base class to store characteristics about a loan. Include customer details in the Loan base class such as name, loan number, and amount of loan. Define subclasses of auto loan and home loan. Include unique characteristics in the derived classes. For example you might include details about the specific auto in the auto loan class and details about the home in the home loan class. Create a presentation class to test your design by...
In C# Create classes: Person, Student, Employee, Professor, Staff and Address ☐ Address class must have...
In C# Create classes: Person, Student, Employee, Professor, Staff and Address ☐ Address class must have suitable auto-implemented properties for Address 1, Address 2 and City. ☐ Person class must have suitable auto-implemented properties for Name, Residence (type Address) and email. ☐ Student and Employee must be subclasses of Person. ☐ Employee must be a super class for Professor and Staff. ☐ Employee class must have suitable auto-implemented properties for salary (between 2000 to 8000), and hire date. ☐ Professor...
Code, pls. Thank you. Exercise - MPG Calculator Create a Windows Forms application and call it...
Code, pls. Thank you. Exercise - MPG Calculator Create a Windows Forms application and call it MPGCalculator Build a form that looks like the form in the video provided. The form consists of 4 labels, 2 textboxes and 3 buttons Name all controls properly. Certain labels do not have to be named Pay attention to video and set all design time properties accordingly. The "x" should be a hot key for the exit button When Calculate is clicked, you should...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
The controller of a small business received the following e-mail with an authentic-looking e-mail address and...
The controller of a small business received the following e-mail with an authentic-looking e-mail address and logo: From: Big Bank [[email protected]] To: Justin Lewis, Controller, Small Business USA Subject: Official Notice for all users of Big Bank! Due to the increased incidence of fraud and identity theft, we are asking all bank customers to verify their account information on the following web page: www.antifraudbigbank.com Please confirm your account information as soon as possible. Failure to confirm your account information will...
Create a Java windows application to manage a list of stocks 1. Add a class Stock...
Create a Java windows application to manage a list of stocks 1. Add a class Stock with the following fields: companyName, pricePerShare, numberOfShares (currently owned) and commission (this is the percent you pay a financial company when you purchase or sell stocks. Add constructor, getters and methods: ***purchaseShares (method that takes the number of shares purchased, updates the stock and return the cost of purchasing these shares make sure to include commission. ***sellShares (method that takes the number of shares...
Create a Windows application in C# that can be used to change the form color. Your...
Create a Windows application in C# that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices and a Reset option. Change the font style and size on buttons. Align the buttons so that they are in the center of the form. The color choice buttons should be the same size. Add event handlers for the buttons so that when the user click the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT