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

namespace ListBox_Simple
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btn_Add;
private System.Windows.Forms.Button btn_Get;
private System.Windows.Forms.ListBox lst_Fruits;
private System.Windows.Forms.Label lbl_FruitSelected;
private System.Windows.Forms.TextBox txt_NewFruit;
/// <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.lst_Fruits = new System.Windows.Forms.ListBox();
this.btn_Add = new System.Windows.Forms.Button();
this.btn_Get = new System.Windows.Forms.Button();
this.lbl_FruitSelected = new System.Windows.Forms.Label();
this.txt_NewFruit = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// lst_Fruits
//
this.lst_Fruits.Items.AddRange(new object[] {
"Apple",
"Banana",
"Orange",
"Pear",
"Plum"});
this.lst_Fruits.Location = new System.Drawing.Point(48, 32);
this.lst_Fruits.Name = "lst_Fruits";
this.lst_Fruits.Size = new System.Drawing.Size(200, 121);
this.lst_Fruits.TabIndex = 0;
//
// btn_Add
//
this.btn_Add.Location = new System.Drawing.Point(64, 216);
this.btn_Add.Name = "btn_Add";
this.btn_Add.TabIndex = 1;
this.btn_Add.Text = "Add Item:";
this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
//
// btn_Get
//
this.btn_Get.Location = new System.Drawing.Point(64, 248);
this.btn_Get.Name = "btn_Get";
this.btn_Get.Size = new System.Drawing.Size(128, 23);
this.btn_Get.TabIndex = 2;
this.btn_Get.Text = "Get Current Selection";
this.btn_Get.Click += new System.EventHandler(this.btn_Get_Click);
//
// lbl_FruitSelected
//
this.lbl_FruitSelected.BackColor = System.Drawing.Color.Red;
this.lbl_FruitSelected.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lbl_FruitSelected.Location = new System.Drawing.Point(72, 176);
this.lbl_FruitSelected.Name = "lbl_FruitSelected";
this.lbl_FruitSelected.Size = new System.Drawing.Size(120, 23);
this.lbl_FruitSelected.TabIndex = 3;
//
// txt_NewFruit
//
this.txt_NewFruit.Location = new System.Drawing.Point(152, 216);
this.txt_NewFruit.Name = "txt_NewFruit";
this.txt_NewFruit.Size = new System.Drawing.Size(88, 20);
this.txt_NewFruit.TabIndex = 4;
this.txt_NewFruit.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 293);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txt_NewFruit,
this.lbl_FruitSelected,
this.btn_Get,
this.btn_Add,
this.lst_Fruits});
this.Name = "Form1";
this.Text = "Simple List Box";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btn_Add_Click(object sender, System.EventArgs e)
{
lst_Fruits.Items.Add(txt_NewFruit.Text);
txt_NewFruit.Text = "";
}

private void btn_Get_Click(object sender, System.EventArgs e)
{
int i = lst_Fruits.SelectedIndex;
lbl_FruitSelected.Text = lst_Fruits.Items[i].ToString();
}
}
}