} // Add

        /// <summary>
        /// Removes a component or a control from the manager.
        /// </summary>
        /// <param name="control">The control being removed.</param>
        internal static void Remove(Control control)
        {
            if (control != null)
            {
                if (control.Focused) 
                    control.Focused = false;
                RootControls.Remove(control);
                // Remove event
                WindowResize -= control.OnParentResize;
            }
        } // Remove
        } // ProcessArrows

        private static void MouseDownProcess(object sender, MouseEventArgs e)
        {
            ControlsList controlList = new ControlsList();
            controlList.AddRange(OrderList);

            if (AutoUnfocus && focusedControl != null && focusedControl.Root != modalWindow)
            {
                bool hit = RootControls.Any(cx => cx.ControlRectangle.Contains(e.Position));

                if (!hit)
                {
                    if (Control.ControlList.Any(t => t.Visible && t.Detached && t.ControlRectangle.Contains(e.Position)))
                    {
                        hit = true;
                    }
                }
                if (!hit) focusedControl.Focused = false;
            }

            for (int i = controlList.Count - 1; i >= 0; i--)
            {
                if (CheckState(controlList[i]) && CheckPosition(controlList[i], e.Position))
                {
                    states.Buttons[(int)e.Button] = controlList[i];
                    controlList[i].SendMessage(Message.MouseDown, e);

                    if (states.Click == -1)
                    {
                        states.Click = (int)e.Button;

                        if (FocusedControl != null)
                        {
                            FocusedControl.Invalidate();
                        }
                        controlList[i].Focused = true;
                    }
                    return;
                }
            }

            if (ModalWindow != null)
            {
                //SystemSounds.Beep.Play();
            }
            else // If we click the window background. This prevent a bug.
            {
                FocusedControl = null;
            }
        } // MouseDownProcess
        } // SortLevel

        #endregion

        #region Add or Remove

        /// <summary>
        /// Adds a control to the manager.
        /// </summary>
        /// <param name="control">The control being added.</param>
        internal static void Add(Control control)
        {
            if (control != null)
            {
                // If the control father is the manager...
                if (!RootControls.Contains(control))
                {
                    if (control.Parent != null) 
                        control.Parent.Remove(control);
                    RootControls.Add(control);
                    control.Parent = null;
                    if (focusedControl == null) 
                        control.Focused = true;
                    WindowResize += control.OnParentResize;
                }
            }
        } // Add
            } // FormClosing

        #endif

        #endregion

        #region Dispose Controls

        /// <summary>
        /// Dispose all controls added to the manager and its child controls.
        /// </summary>
        public static void DisposeControls()
        {
            try
            {
                for (int i = 0; i < RootControls.Count; i++)
                {
                    RootControls[i].Dispose();
                }
                RootControls.Clear();
                OrderList.Clear();
                FocusedControl = null;
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("User Interface Manager: Unable to dispose controls. Was the User Interface Manager started?", e);
            }
        } // DisposeControls