using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace FileStreamWrite
{
    public class Form1 : System.Windows.Forms.Form
  {
               #region ...Omitted designer generated code
              internal System.Windows.Forms.Button exitButton;
                internal System.Windows.Forms.Button saveButton;
                internal System.Windows.Forms.Label Label2;
             internal System.Windows.Forms.Label Label1;
             internal System.Windows.Forms.TextBox phoneTextBox;
             internal System.Windows.Forms.TextBox nameTextBox;
              /// <summary>
           /// Required designer variable.
         /// </summary>
          private System.ComponentModel.Container components = null;

              public Form1()
          {
                       //
                      // Required for Windows Form Designer support
                   //
                      InitializeComponent();

                  //
                      // TODO: Add any constructor code after InitializeComponent call
                        //
              }

               /// <summary>
           /// Clean up any resources being used.
          /// </summary>
          protected override void Dispose( bool disposing )
               {
                       if( disposing )
                 {
                               if (components != null) 
                                {
                                       components.Dispose();
                           }
                       }
                       base.Dispose( disposing );
              }


               #region Windows Form Designer generated code
            /// <summary>
           /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
           /// </summary>
          private void InitializeComponent()
              {
                       this.exitButton = new System.Windows.Forms.Button();
                    this.saveButton = new System.Windows.Forms.Button();
                    this.Label2 = new System.Windows.Forms.Label();
                 this.Label1 = new System.Windows.Forms.Label();
                 this.phoneTextBox = new System.Windows.Forms.TextBox();
                 this.nameTextBox = new System.Windows.Forms.TextBox();
                  this.SuspendLayout();
                   // 
                     // exitButton
                   // 
                     this.exitButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                        this.exitButton.Location = new System.Drawing.Point(132, 198);
                  this.exitButton.Name = "exitButton";
                    this.exitButton.TabIndex = 5;
                   this.exitButton.Text = "E&xit";
                 this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
                        // 
                     // saveButton
                   // 
                     this.saveButton.Location = new System.Drawing.Point(132, 158);
                  this.saveButton.Name = "saveButton";
                    this.saveButton.TabIndex = 4;
                   this.saveButton.Text = "&Save";
                 this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
                        // 
                     // Label2
                       // 
                     this.Label2.Location = new System.Drawing.Point(36, 86);
                        this.Label2.Name = "Label2";
                    this.Label2.TabIndex = 2;
                       this.Label2.Text = "&Phone";
                    // 
                     // Label1
                       // 
                     this.Label1.Location = new System.Drawing.Point(36, 46);
                        this.Label1.Name = "Label1";
                    this.Label1.TabIndex = 0;
                       this.Label1.Text = "&Name";
                     // 
                     // phoneTextBox
                 // 
                     this.phoneTextBox.Location = new System.Drawing.Point(156, 86);
                 this.phoneTextBox.Name = "phoneTextBox";
                        this.phoneTextBox.TabIndex = 3;
                 this.phoneTextBox.Text = "";
                    // 
                     // nameTextBox
                  // 
                     this.nameTextBox.Location = new System.Drawing.Point(156, 46);
                  this.nameTextBox.Name = "nameTextBox";
                  this.nameTextBox.TabIndex = 1;
                  this.nameTextBox.Text = "";
                     // 
                     // PhoneForm
                    // 
                     this.AcceptButton = this.saveButton;
                    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                        this.CancelButton = this.exitButton;
                    this.ClientSize = new System.Drawing.Size(296, 246);
                    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                                                                               this.exitButton,
                                                                                                                                                this.saveButton,
                                                                                                                                                this.Label2,
                                                                                                                                            this.Label1,
                                                                                                                                            this.phoneTextBox,
                                                                                                                                              this.nameTextBox});
                   this.Name = "PhoneForm";
                        this.Text = "Create Name Phone File";
                   this.ResumeLayout(false);

               }
               #endregion
              #endregion
              
                StreamWriter phoneStreamWriter = new StreamWriter("Phone.txt");
         //By default, the file will appear in the bin/Debug folder of this project

              [STAThread]
             static void Main() 
             {
                       Application.Run(new Form1());
           }

               private void exitButton_Click(object sender, System.EventArgs e)
                {
                       //End the project

                       phoneStreamWriter.Close();
                      this.Close();
           }

               private void saveButton_Click(object sender, System.EventArgs e)
                {
                       //Save the record to the file

                   phoneStreamWriter.WriteLine(nameTextBox.Text);
                  phoneStreamWriter.WriteLine(phoneTextBox.Text);
                 nameTextBox.Clear();
                    phoneTextBox.Clear();
                   nameTextBox.Focus();
            }
       }
}