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

namespace CPress
{
    public class StateListBox : WebPart
    {
        private String _LabelStartText = " Zadejte nzev sttu: ";
        readonly TextBox StateInput = new TextBox();
        readonly ListBox StateContents = new ListBox();

        public StateListBox()
        {
            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;
            Controls.Add(InstructionText);

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

            Controls.Add(StateInput);

            Button InputButton = new Button();
            InputButton.Text = "Zadat stt";
            InputButton.Click += this.Button1_Click;
            Controls.Add(InputButton);

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

            Controls.Add(StateContents);

            ChildControlsCreated = true;
        }

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