/// <summary>
        /// Adds a link node.
        /// </summary>
        /// <param name="root"> The root node.</param>
        /// <param name="text"> The node text.</param>
        /// <param name="tag"> The HtmlALinkTag.</param>
        public void AddALink(FormEditorNode root, string text,HtmlALinkTag tag)
        {
            FormEditorNode node = new FormEditorNode();

            // add it to root node
            root.Nodes.Add(node);
            node.BaseHtmlTag = tag;
            node.Text = text;
        }
        /// <summary>
        /// Adds a control.
        /// </summary>
        /// <param name="label"> The control label value.</param>
        /// <param name="control"> The control to add.</param>
        public void AddControl(string label, Control control)
        {
            FormEditorNode newNode = new FormEditorNode();
            newNode.Text = label;
            newNode.NodeControl = control;

            Label l = new Label();
            l.Size = new Size(control.Width, control.Height);
            l.Text=control.Text;
            newNode.LabelControl=l;

            this.Nodes.Add(newNode);
        }
        private void AddInputNode(FormEditorNode node, HtmlInputTag input)
        {
            string label;
            label = "<input ";
            label +=" type="+ input.Type;
            label +=" name="+ input.Name;
            label +=" value="+ input.Value;
            label +="/>";

            formEditor.AddInput(node,label,input);
        }
        private void AddButtonNode(FormEditorNode node, HtmlButtonTag button)
        {
            string label;
            label = "<button ";
            label +=" name="+ button.Name;
            label +=" value="+ button.Value;
            label +="/>";

            //tree.AddButton(node,button);
        }
        private void AddALinkNode(FormEditorNode node, HtmlALinkTag a)
        {
            if ( a.HRef.IndexOf("javascript") > -1 )
            {
                string label;

                label = "<a ";
                label +=" href="+ a.HRef;
                label +=" id="+ a.Id;
                label +=" onclick="+ a.OnClick;
                label +="/>";

                formEditor.AddALink(node,label,a);
            }
        }
        /// <summary>
        /// Loads the forms into the form tree.
        /// </summary>
        /// <param name="forms"></param>
        public void LoadFormTree(HtmlFormTagCollection forms)
        {
            formEditor.Clear();

            foreach (DictionaryEntry de in forms)
            {
                HtmlFormTag form = (HtmlFormTag)de.Value;

                StringBuilder label = new StringBuilder();
                // add Form node
                label.Append("<form name=");
                label.Append((string)de.Key);
                label.Append(" method=");
                label.Append(form.Method);
                label.Append(" action=");
                label.Append(form.Action);

                if ( form.OnSubmit != null )
                {
                    if ( form.OnSubmit.Length > 0 )
                    {
                        label.Append(" onsubmit=");
                        label.Append(form.OnSubmit);
                    }
                }
                label.Append(">");

                FormEditorNode formNode = formEditor.AddFormNode(label.ToString(),form);

                for (int i=0;i<form.Count;i++)
                {
                    FormEditorNode child = new FormEditorNode();
                    HtmlTagBaseList controlArray = (HtmlTagBaseList)((DictionaryEntry)form[i]).Value;

                    foreach (HtmlTagBase tag in controlArray)
                    {
                        if (tag is HtmlALinkTag)
                        {
                            HtmlALinkTag a=(HtmlALinkTag)tag;
                            AddALinkNode(formNode, a);
                        }

                        if (tag is HtmlInputTag)
                        {
                            HtmlInputTag input=(HtmlInputTag)tag;
                            AddInputNode(formNode,input);

                        }

                        if (tag is HtmlButtonTag)
                        {
                            HtmlButtonTag button = (HtmlButtonTag)tag;
                            AddButtonNode(formNode,button);
                        }

                        if (tag is HtmlSelectTag)
                        {
                            HtmlSelectTag select = (HtmlSelectTag)tag;
                            AddSelectNode(formNode,select);
                        }

                        if (tag is HtmlTextAreaTag)
                        {
                            HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;
                            AddTextAreaNode(formNode,textarea);
                        }
                    }
                }
            }

            formEditor.ExpandAll();
        }
        /// <summary>
        /// Adds a FormNode and returns the added node.
        /// </summary>
        /// <param name="text"> The node text.</param>
        /// <param name="formtag"> The HtmlFormTag.</param>
        /// <returns> Returns a FormEditorNode.</returns>
        public FormEditorNode AddFormNode(string text, HtmlFormTag formtag)
        {
            FormEditorNode node = new FormEditorNode();
            node.Text=text;
            node.BaseHtmlTag=formtag;
            this.Nodes.Add(node);

            return node;
        }
        /// <summary>
        /// Adds a ListBox control.
        /// </summary>
        /// <param name="label"> The control label value.</param>
        /// <param name="control"> The control to add.</param>
        /// <param name="doubleClickHandler"> The double click event handler to attach.</param>
        /// <param name="selectValueChangedHandler"> The selected value event handler to attach.</param>
        internal void AddListBoxControl(string label, ListBox control,EventHandler doubleClickHandler, EventHandler selectValueChangedHandler)
        {
            FormEditorNode newNode = new FormEditorNode();
            newNode.Text=label;
            control.DoubleClick += doubleClickHandler;
            control.SelectedValueChanged+=selectValueChangedHandler;
            control.Tag = this;
            newNode.NodeControl=control;

            Label l = new Label();
            l.Size = new Size(control.Width, control.Height);
            if ( control.SelectedItems.Count > 0 )
            {
                l.Text = (string)control.SelectedValue;
            }
            else
            {
                l.Text = ((HtmlSelectTag)this.BaseHtmlTag).Value;
                control.SelectedValue = l.Text;
            }
            newNode.LabelControl=l;

            this.Nodes.Add(newNode);
        }
        private void SetInputTextareaValue(HtmlFormTag form, string tagName, string name, string value)
        {
            for (int i=0;i<form.Count;i++)
            {
                FormEditorNode child = new FormEditorNode();
                HtmlTagBaseList controlArray = (HtmlTagBaseList)((DictionaryEntry)form[i]).Value;
                int controlIndex = 0;

                #region inner loop
                foreach (HtmlTagBase tag in controlArray)
                {
                    // Input tags
                    if ( (tag is HtmlInputTag) && (tagName.ToLower() == "input") )
                    {
                        HtmlInputTag input=(HtmlInputTag)tag;
                        if ( input.Name == name )
                        {
                            input.Value = value;
                            return;
                        }
                    }

                    // Textarea tags
                    if ( (tag is HtmlTextAreaTag) && (tagName.ToLower()=="textarea") )
                    {
                        HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;

                        if ( textarea.Name == name )
                        {
                            textarea.Value = value;
                            return;
                        }
                    }

                    controlIndex++;
                }
                #endregion
            }
        }
        /// <summary>
        /// Sets a value for a html tag.
        /// </summary>
        /// <param name="selectedNode"></param>
        /// <param name="value"></param>
        private void SetHtmlTagValue(FormEditorNode selectedNode, string value)
        {
            // Get the tag, label and control
            HtmlTagBase tag = selectedNode.BaseHtmlTag;
            Label label = ((FormEditorNode)selectedNode.Nodes[0]).LabelControl;
            Control control = ((FormEditorNode)selectedNode.Nodes[0]).NodeControl;

            if ( tag is HtmlInputTag )
            {
                ((HtmlInputTag)tag).Value  = value;
                ((TextBox)control).Text = value;
                label.Text = value;
            }
            if ( tag is HtmlSelectTag )
            {
                HtmlSelectTag selectTag = (HtmlSelectTag)tag;
                ListBox wfSelect = (ListBox)control;

                // set values to Windows Form Listbox
                for (int i=0;i<wfSelect.SelectedIndices.Count;i++ )
                {
                    int index = wfSelect.SelectedIndices[i];
                    wfSelect.Items[index] = value;
                    selectTag.UpdateOptionValue(index,value);
                }

                label.Text = value;
            }
            if ( tag is HtmlButtonTag )
            {
                ((HtmlButtonTag)tag).Value = value;
                ((TextBox)control).Text = value;
                label.Text = value;
            }
            if ( tag is HtmlTextAreaTag )
            {
                ((HtmlTextAreaTag)tag).Value = value;
                ((TextBox)control).Text = value;
                label.Text = value;
            }
        }
        /// <summary>
        /// Adds a button node.
        /// </summary>
        /// <param name="text">The node text.</param>
        /// <param name="button"> The HtmlButtonTag.</param>
        public void AddButton(string text,HtmlButtonTag button)
        {
            FormEditorNode node = new FormEditorNode();
            node.Text=text;
            node.BaseHtmlTag = button;

            TextBox[] textboxes;
            textboxes = GetTextBoxArray(1);
            textboxes = GetTextBoxArray(1);
            textboxes[0].Name = "txtValue";
            textboxes[0].Text = button.Value;
            node.AddControl("Value:",textboxes[0]);
        }
        /// <summary>
        /// Adds a TextArea node.
        /// </summary>
        /// <param name="root"> The root node.</param>
        /// <param name="text"> The node text.</param>
        /// <param name="tag"> The HtmlTextAreaTag.</param>
        public void AddTextArea(FormEditorNode root, string text,HtmlTextAreaTag tag)
        {
            FormEditorNode node = new FormEditorNode();

            // add it to root node
            root.Nodes.Add(node);

            node.Text=text;
            node.BaseHtmlTag = tag;

            TextBox[] textboxes;

            textboxes = GetTextBoxArray(1);
            textboxes[0].Size = new Size(300,15);
            textboxes[0].Name = "txtValue";
            textboxes[0].Text = tag.Value;
            node.AddTextControl("Value:",textboxes[0],new EventHandler(TextAreaChangeValue));
        }
        /// <summary>
        /// Adds a Select node.
        /// </summary>
        /// <param name="root"> The root node.</param>
        /// <param name="text"> The node text.</param>
        /// <param name="tag"> The HtmlSelectTag.</param>
        public void AddSelect(FormEditorNode root, string text,HtmlSelectTag tag)
        {
            FormEditorNode node = new FormEditorNode();

            // add it to root node
            root.Nodes.Add(node);

            node.Text=text;
            node.BaseHtmlTag = tag;

            if ( tag.Multiple )
            {
                ListBox lst = new ListBox();
                //lst.HorizontalScrollbar=true;
                //lst.DoubleClick+=new EventHandler(ListBox_DoubleClick);
                lst.Size=new Size(200,30);
                lst.BackColor=Color.WhiteSmoke;
                lst.ForeColor=Color.Blue;
                foreach (HtmlOptionTag opt in tag.Options)
                {
                    lst.Items.Add(opt.Value);
                }
                //lst.Name="lstList";
                lst.SelectionMode=SelectionMode.MultiExtended;
                this.ItemHeight=25;

                node.AddListBoxControl("Values:",lst,new EventHandler(ListBox_DoubleClick),new EventHandler(ListBox_SelectedValueChanged));
            }
            else
            {
                ListBox lst = new ListBox();
                //lst.DropDownStyle=ComboBoxStyle.DropDown;
                lst.Size=new Size(200,30);
                lst.BackColor=Color.WhiteSmoke;
                lst.ForeColor=Color.Blue;
                foreach ( HtmlOptionTag opt in tag.Options)
                {
                    lst.Items.Add(opt.Value);
                }
                //lst.Name="cmbList";
                lst.SelectionMode=SelectionMode.One;
                this.ItemHeight=25;

                node.AddListBoxControl("Values:",lst,new EventHandler(ListBox_DoubleClick),new EventHandler(ListBox_SelectedValueChanged));
            }
        }
        /// <summary>
        /// Adds a Input node.
        /// </summary>
        /// <param name="root"> The root node.</param>
        /// <param name="text"> The node text.</param>
        /// <param name="inputTag"> The HtmlInputTag.</param>
        public void AddInput(FormEditorNode root, string text,HtmlInputTag inputTag)
        {
            FormEditorNode node = new FormEditorNode();

            // add it to root node
            root.Nodes.Add(node);

            node.Text=text;
            node.BaseHtmlTag = inputTag;

            TextBox[] textboxes;

            switch (inputTag.Type)
            {
                case HtmlInputType.Button:
                    textboxes = GetTextBoxArray(1);
                    textboxes[0].Name = "txtValue";
                    textboxes[0].Text = inputTag.Value;
                    node.AddTextControl("Value:",textboxes[0],new EventHandler(TextChangeValue));
                    break;
                case HtmlInputType.Checkbox:
                    textboxes = GetTextBoxArray(1);
                    textboxes[0].Name = "txtValue";
                    textboxes[0].Text = inputTag.Value;
                    node.AddTextControl("Value:",textboxes[0],new EventHandler(TextChangeValue));
                    break;
                case HtmlInputType.Text:
                    textboxes = GetTextBoxArray(1);
                    textboxes[0].Name = "txtValue";
                    textboxes[0].Text = inputTag.Value;
                    node.AddTextControl("Value:",textboxes[0],new EventHandler(TextChangeValue));
                    break;
                case HtmlInputType.Submit:
                    textboxes = GetTextBoxArray(1);
                    textboxes[0].Name = "txtValue";
                    textboxes[0].Text = inputTag.Value;
                    node.AddTextControl("Value:",textboxes[0],new EventHandler(TextChangeValue));
                    break;
                case HtmlInputType.Password:
                    textboxes = GetTextBoxArray(1);
                    textboxes[0].Name = "txtValue";
                    textboxes[0].Text = inputTag.Value;
                    node.AddTextControl("Value:",textboxes[0],new EventHandler(TextChangeValue));
                    break;
                default:
                    textboxes = GetTextBoxArray(1);
                    textboxes[0].Name = "txtValue";
                    textboxes[0].Text = inputTag.Value;
                    node.AddTextControl("Value:",textboxes[0],new EventHandler(TextChangeValue));
                    break;
            }
        }
        private void AddSelectNode(FormEditorNode node,HtmlSelectTag select)
        {
            string label;
            label = "<select ";
            label +=" name="+ select.Name;
            if ( select.Multiple )
            {
                label += " multiple";
            }
            label +="/>";

            formEditor.AddSelect(node,label,select);
        }
        private void LoadFormTree(HtmlFormTagCollection forms)
        {
            foreach (DictionaryEntry de in forms)
            {
                HtmlFormTag form = (HtmlFormTag)de.Value;

                StringBuilder label = new StringBuilder();
                // add Form node
                label.Append("<form name=");
                label.Append((string)de.Key);
                label.Append(" method=");
                label.Append(form.Method);
                label.Append(" action=");
                label.Append(form.Action);
                if ( form.OnSubmit.Length > 0 )
                {
                    label.Append(" onsubmit=");
                    label.Append(form.OnSubmit);
                }
                label.Append(">");

                FormEditorNode formNode = formsTree.AddFormNode(label.ToString(),form);

                foreach (DictionaryEntry dd in form)
                {
                    FormEditorNode child = new FormEditorNode();
                    HtmlTagBaseList controlArray = (HtmlTagBaseList)dd.Value;

                    foreach (HtmlTagBase tag in controlArray)
                    {
            //						if (tag is HtmlALinkTag)
            //						{
            //							HtmlALinkTag a=(HtmlALinkTag)tag;
            //							AddALinkNode(formNode, a);
            //						}

                        if (tag is HtmlInputTag)
                        {
                            HtmlInputTag input=(HtmlInputTag)tag;
                            FormEditorNode node = new FormEditorNode();
                            node.Text = input.Name + "=" + input.Value;
                            formNode.Nodes.Add(node);
                            //AddInputNode(formNode,input);

                        }

                        if (tag is HtmlButtonTag)
                        {
                            HtmlButtonTag button = (HtmlButtonTag)tag;
                            FormEditorNode node = new FormEditorNode();
                            node.Text = button.Name + "=" + button.Value;
                            formNode.Nodes.Add(node);
                            //AddButtonNode(formNode,button);
                        }

                        if (tag is HtmlSelectTag)
                        {
                            HtmlSelectTag select = (HtmlSelectTag)tag;
                            FormEditorNode node = new FormEditorNode();
                            node.Text = select.Name + "=" + select.Value;
                            formNode.Nodes.Add(node);
                            //AddSelectNode(formNode,select);
                        }

                        if (tag is HtmlTextAreaTag)
                        {
                            HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;
                            FormEditorNode node = new FormEditorNode();
                            node.Text = textarea.Name + "=" + textarea.Value;
                            formNode.Nodes.Add(node);
                            //AddTextAreaNode(formNode,textarea);
                        }
                    }
                }
            }
        }
        private void AddTextAreaNode(FormEditorNode node,HtmlTextAreaTag textarea)
        {
            string label;
            label = "<textarea ";
            label +=" name="+ textarea.Name;
            label +=">";
            label +=textarea.Value;
            label +="</textarea>";

            formEditor.AddTextArea(node,label,textarea);
        }
        private void mnuSelectForm_Click(object sender, System.EventArgs e)
        {
            if ( tempSelectedNode != null )
            {
                // revert saved selection
                tempSelectedNode.BackColor = formsTree.BackColor;
            }

            formsTree.SelectedNode.BackColor = Color.Yellow;
            tempSelectedNode = formsTree.SelectedNode;
            this.SelectedForm = ((HtmlFormTag)formsTree.SelectedNode.BaseHtmlTag);
        }
        /// <summary>
        /// Adds a textbox control.
        /// </summary>
        /// <param name="label"> The control label value.</param>
        /// <param name="control"> The control to add.</param>
        /// <param name="eventHandler"> The event handler to attach.</param>
        internal void AddTextControl(string label, TextBox control,EventHandler eventHandler)
        {
            FormEditorNode newNode = new FormEditorNode();
            newNode.Text = label;
            control.TextChanged += eventHandler;
            control.Tag = this;
            newNode.NodeControl = control;

            Label l = new Label();
            l.Size = new Size(control.Width, control.Height);
            l.Text = control.Text;
            newNode.LabelControl=l;

            this.Nodes.Add(newNode);
        }
        /// <summary>
        /// Displays a message indicating that no data could be showed.
        /// </summary>
        public void DisplayNoDataMessage()
        {
            formEditor.Clear();

            FormEditorNode node = new FormEditorNode();
            node.Text = "No data available for display";
            formEditor.Nodes.Add(node);
        }
        /// <summary>
        /// Adds a ComboBox control.
        /// </summary>
        /// <param name="label"> The control label value.</param>
        /// <param name="control"> The control to add.</param>
        /// <param name="eventHandler"> The event handler to attach.</param>
        internal void AddComboBoxControl(string label, ComboBox control,EventHandler eventHandler)
        {
            FormEditorNode newNode = new FormEditorNode();
            newNode.Text=label;
            control.SelectedIndexChanged+=eventHandler;
            control.Tag = this;
            newNode.NodeControl=control;

            Label l = new Label();
            l.Size = new Size(control.Width, control.Height);
            l.Text = (string)control.SelectedValue;
            newNode.LabelControl=l;

            this.Nodes.Add(newNode);
        }
 /// <summary>
 /// Adds a Form Node.
 /// </summary>
 /// <param name="node"> A FormEditorNode to add.</param>
 /// <param name="text"> The node text.</param>
 /// <param name="formtag"> The HtmFormTag.</param>
 public void AddFormNode(FormEditorNode node,string text, HtmlFormTag formtag)
 {
     node.Text=text;
     node.BaseHtmlTag=formtag;
     this.Nodes.Add(node);
 }