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 lab6
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            String [] a = File.ReadAllLines(@"D:\\nghiadaica1.txt");
            for (int i = 0; i < a.Length; i++)
            {
                listBox1.Items.Add(a[i]);
            }
            
            
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            String a = listBox1.SelectedItem.ToString();
            listBox1.Items.Remove(a);
            String[] line = File.ReadAllLines(@"D:\\nghiadaica1.txt");
            for (int i = 0; i < line.Length; i++)
            {
                if (line[i].CompareTo(a) == 0)
                {
                    line[i] = null;
                }
            }
            StreamWriter a1 = File.CreateText(@"D:\\nghiadaica1.txt");
            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] != null)
                {
                    a1.WriteLine(line[i]);
                    a1.Flush();
                }
                
            }
            a1.Close();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Dispose();
           Main a = new Main();
            a.ShowDialog();

        }
    }
}
