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;

namespace ch4_7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void AddButton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
                MessageBox.Show("Please enter a book", "No book entered",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            else
                listBox1.Items.Add(textBox1.Text);
            textBox1 .Text = "";
        }

        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (listBox1 .SelectedIndex == -1)
                MessageBox.Show("Please select an item first", "No book entered",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            else
                listBox1.Items.Remove(listBox1 .SelectedIndex );
            textBox1 .Text = "";
        }

        private void ClearButton_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }

        private void SortedButton_Click(object sender, EventArgs e)
        {
            listBox1.Sorted = true;
        }
    }
}
