using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Wrox
{
    public class StateListBox : WebPart
    {
        private String _LabelStartText = " Wpisz nazwę stanu: ";
        readonly TextBox StateInput = new TextBox();
        readonly ListBox StateContents = new ListBox();

        public StateListBox()
        {
            this.AllowClose = false;
        }

        [Personalizable(), WebBrowsable]
        public String LabelStartText
        {
            get { return _LabelStartText; }
            set { _LabelStartText = value; }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();

            Label InstructionText = new Label();
            InstructionText.BackColor = System.Drawing.Color.LightGray;
            InstructionText.Font.Name = "Verdana";
            InstructionText.Font.Size = 10;
            InstructionText.Font.Bold = true;
            InstructionText.Text = LabelStartText;
            this.Controls.Add(InstructionText);

            Literal LineBreak = new Literal();
            LineBreak.Text = "<br />";
            this.Controls.Add(LineBreak);

            this.Controls.Add(StateInput);

            Button InputButton = new Button();
            InputButton.Text = "Wprowad stan";
            InputButton.Click += new EventHandler(this.Button1_Click);
            this.Controls.Add(InputButton);

            Literal Spacer = new Literal();
            Spacer.Text = "<p>";
            this.Controls.Add(Spacer);

            this.Controls.Add(StateContents);

            ChildControlsCreated = true;
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            StateContents.Items.Add(StateInput.Text);
            StateInput.Text = String.Empty;
            StateInput.Focus();
        }
    }
}
