Wednesday, 22 May 2013

C# Save information using filing

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;


namespace save
{
    public partial class Form1 : Form
    {
        //class level variables
        string[] phoneData = new string[10];
        int indexInteger;

        public Form1()
        {
            InitializeComponent();
        }

        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //write to the file
            File.WriteAllLines("TextFile.txt", phoneData);
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            //add to the array
            phoneData[indexInteger++] = nameTextBox.Text;
            phoneData[indexInteger++] = phoneTextBox.Text;

            // clear the fields for the next record
            phoneTextBox.Clear();
            nameTextBox.Clear();
            nameTextBox.Focus();
        }

       

    }
}

No comments:

Post a Comment