/// <summary>
        /// Adds a <see cref="DockPanel"/> to the container.
        /// </summary>
        /// <param name="src">The source panel.></param>
        /// <param name="dst">The destination container.</param>
        internal void AddPanel(DockPanel src, DockContainer dst)
        {
            if ((src == null) | (dst == null))
                return;

            try
            {
                blockFocusEvents = true;

                if (dst == this)
                {
                    this.Controls.Add(src);
                }
                else
                {
                    dst.Controls.Add(src);
                    this.Controls.Add(dst);
                }

                blockFocusEvents = false;
            }
            catch (Exception e)
            {
                Console.WriteLine("DockContainer.AddPanel: " + e.Message);
            }
        }
        /// <summary>
        /// Selects a specific tab based on its reference pointer.
        /// </summary>
        /// <param name="p">The tab reference.</param>
        public void SelectTab(DockPanel p)
        {
            try
            {
                if ((panList != null) && (p != null))
                {
                    if (!panList.Contains(p))
                        return;

                    ActivePanel = p;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("DockContainer.SelectTab: " + e.Message);
            }
        }
        /// <summary>
        /// Reads the container data from the window save list.
        /// </summary>
        /// <param name="reader">The <see cref="XmlReader"/> object that reads from the source stream.</param>
        internal virtual void ReadXml(XmlReader reader)
        {
            reader.Read();
            //disableOnControlAdded = true;

            if (!(this is DockManager))
            {
                string s;

                switch (reader.GetAttribute("dock"))
                {
                    case "Fill":
                        this.Dock = DockStyle.Fill;
                        break;
                    case "Top":
                        this.Dock = DockStyle.Top;
                        break;
                    case "Bottom":
                        this.Dock = DockStyle.Bottom;
                        break;
                    case "Left":
                        this.Dock = DockStyle.Left;
                        break;
                    case "Right":
                        this.Dock = DockStyle.Right;
                        break;
                    default:
                        disableOnControlAdded = false;
                        return;
                }

                s = reader.GetAttribute("width");
                if (s != null)
                    this.Width = int.Parse(s);

                s = reader.GetAttribute("height");
                if (s != null)
                    this.Height = int.Parse(s);

                switch (reader.GetAttribute("type"))
                {
                    case "Document":
                        this.DockType = DockContainerType.Document;
                        break;
                    case "ToolWindow":
                        this.DockType = DockContainerType.ToolWindow;
                        break;
                    default:
                        disableOnControlAdded = false;
                        return;
                }
            }

            while (reader.Read())
            {
                if (!reader.IsStartElement())
                    continue;

                if (reader.Name == "container")
                {
                    Console.WriteLine("container");

                    DockContainer c = new DockContainer();
                    c.ReadXml(reader.ReadSubtree());

                    if (!c.IsEmpty)
                    {
                        this.Controls.Add(c);
                        this.DockPadding.All = 0;
                    }
                }
                else if (reader.Name == "panel")
                {
                    Console.WriteLine("panel");

                    DockPanel p = new DockPanel();
                    p.ReadXml(reader);

                    this.Controls.Add(p);
                }
            }

            disableOnControlAdded = false;
        }
        /// <summary>
        /// Measures the size of a <see cref="DockPanel"/> tab depending on a given font.
        /// </summary>
        /// <param name="panel">The <see cref="DockPanel"/> object.</param>
        /// <param name="graphics">The <see cref="Graphics"/> interface.</param>
        /// <param name="cut">Enables the reduction of the panel size according to the available space.</param>
        /// <param name="font">The target font.</param>
        /// <returns>The size of the panel tab.</returns>
        private SizeF MeasurePanel(DockPanel panel, Graphics graphics, bool cut, Font font)
        {
            SizeF ret = graphics.MeasureString(panel.Form.Text, font);

            if (font.Bold)
                ret.Width += 12;
            else
                ret.Width += 6;

            if (showIcons && (panel.Form.Icon != null))
                ret.Width += ret.Height + 3;

            if ((ret.Width > (this.Width - DockPadding.Left - DockPadding.Right + 2 - 8) / panList.Count) && cut)
                ret.Width = (this.Width - DockPadding.Left - DockPadding.Right + 2 - 8) / panList.Count;

            return ret;
        }
        /// <summary>
        /// A message handler for the Deactivate event of the parent window.
        /// Needed to refresh the child controls.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An <see cref="EventArgs"/> that contains the event data.</param>
        private void DeactivateParent(object sender, EventArgs e)
        {
            try
            {
                foreach (DockPanel p in DockManager.ListDocument)
                {
                    DockContainer c = p.Form.HostContainer;
                    if (c == null)
                        continue;

                    if ((c.ActivePanel == p) && (c.ContainsFocus))
                    {
                        activeDoc = p;
                        p.SetFocus(false);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("DockManager.DeactivateParent: "+ex.Message);
            }
            finally
            {
                Invalidate(true);
            }
        }