using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Telerik.WebControls;

namespace Programmatic
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadToolbar1.Items.Add(GetButton("New", "New Document",
                    "New.gif"));
                RadToolbar1.Items.Add(GetButton("Open", "Open Document",
                    "Open.gif"));
                RadToolbar1.Items.Add(GetButton("Save", "Save Document",
                    "Save.gif"));

                RadToolbar1.Items.Add(new RadToolbarSeparator());
                RadToolbar1.Items.Add(GetToggleButton("Left", "Align Left",
                    "AlignLeft.gif", "Align"));
                RadToolbar1.Items.Add(GetToggleButton("Center", "Align Center",
                    "Center.gif", "Align"));
                RadToolbar1.Items.Add(GetToggleButton("Right", "Align Right",
                    "AlignRight.gif", "Align"));
                RadToolbar1.Items.Add(GetToggleButton("Justify", "Align Justified",
                    "Justify.gif", "Align"));

                RadToolbar1.Items.Add(new RadToolbarSeparator());
                RadToolbar1.Items.Add(GetToggleButton("Bold", "Bold Font",
                    "bold.gif"));
                RadToolbar1.Items.Add(GetToggleButton("Italic", "Italic Font",
                    "Italic.gif"));
                RadToolbar1.Items.Add(GetToggleButton("Underline", "Underline Font",
                    "underline.gif"));
            }
        }

        protected void RadToolbar1_OnClick(object sender, Telerik.WebControls.RadToolbarClickEventArgs e)
        {
            lblStatus.Text = "You clicked on " + e.Button.CommandName;
        }

        private RadToolbarButton GetButton(string command, string tip, string image)
        {
            RadToolbarButton radToolBarButton = new RadToolbarButton();
            radToolBarButton.CommandName = command;
            radToolBarButton.ToolTip = tip;
            radToolBarButton.ButtonImage = image;
            return radToolBarButton;
        }

        private RadToolbarToggleButton GetToggleButton(string command, string tip, string image, string group)
        {
            RadToolbarToggleButton radToolBarToggleButton = new RadToolbarToggleButton();
            radToolBarToggleButton.CommandName = command;
            radToolBarToggleButton.ToolTip = tip;
            radToolBarToggleButton.ButtonImage = image;
            radToolBarToggleButton.ButtonGroup = group;
            return radToolBarToggleButton;
        }

        private RadToolbarToggleButton GetToggleButton(string command, string tip, string image)
        {
            return GetToggleButton(command, tip, image, "");
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            RadToolbarTemplateButton radToolbarTemplateButton = new RadToolbarTemplateButton();
            ToolBarTemplate toolBarTemplate = new ToolBarTemplate();
            radToolbarTemplateButton.ButtonTemplate = toolBarTemplate;

            RadToolbar1.Items.Add(radToolbarTemplateButton);

            TextBox tbSearch = radToolbarTemplateButton.FindControl("tbSearch") as TextBox;
            tbSearch.TextChanged += new EventHandler(tbSearch_TextChanged);
        }

        void tbSearch_TextChanged(object sender, EventArgs e)
        {
            lblStatus.Text = (sender as TextBox).Text;
        }
    }
}
