/// <devdoc>
        ///     Cleans up form state after a control has been removed.
        ///     Package scope for Control
        /// </devdoc>
        /// <internalonly/>
        internal virtual void AfterControlRemoved(Control control)
        {
            if (control == activeControl || control.Contains(activeControl))
            {
                // REGISB: this branch never seems to be reached.
                //         leaving it intact to be on the safe side
                bool selected = SelectNextControl(control, true, true, true, true);
                if (selected)
                {
                    FocusActiveControlInternal();
                }
            }
            else if (activeControl == null && ParentInternal != null)
            {
                // The last control of an active container was removed. Focus needs to be given to the next
                // control in the Form.
                ContainerControl cc = ParentInternal.GetContainerControlInternal() as ContainerControl;
                if (cc != null && cc.ActiveControl == this)
                {
                    Form f = FindFormInternal();
                    if (f != null)
                    {
                        f.SelectNextControl(this, true, true, true, true);
                    }
                }
            }

            if (control == unvalidatedControl || control.Contains(unvalidatedControl))
            {
                unvalidatedControl = null;
            }
        }
        /// <devdoc>
        ///     WM_SETFOCUS handler
        /// </devdoc>
        /// <internalonly/>
        private void WmSetFocus(ref Message m)
        {
            if (!HostedInWin32DialogManager)
            {
                if (ActiveControl != null)
                {
                    ImeSetFocus();
                    // REGISB: Do not raise GotFocus event since the focus
                    //         is given to the visible ActiveControl
                    if (!ActiveControl.Visible)
                    {
                        OnGotFocus(EventArgs.Empty);
                    }
                    FocusActiveControlInternal();
                }
                else
                {
                    if (ParentInternal != null)
                    {
                        IContainerControl c = ParentInternal.GetContainerControlInternal();
                        if (c != null)
                        {
                            bool succeeded = false;

                            ContainerControl knowncontainer = c as ContainerControl;
                            if (knowncontainer != null)
                            {
                                succeeded = knowncontainer.ActivateControlInternal(this);
                            }
                            else
                            {
                                // SECREVIEW : Taking focus and activating a control is response
                                //           : to a user gesture (WM_SETFOCUS) is OK.
                                //
                                IntSecurity.ModifyFocus.Assert();
                                try {
                                    succeeded = c.ActivateControl(this);
                                }
                                finally {
                                    CodeAccessPermission.RevertAssert();
                                }
                            }
                            if (!succeeded)
                            {
                                return;
                            }
                        }
                    }
                    base.WndProc(ref m);
                }
            }
            else
            {
                base.WndProc(ref m);
            }
        }
        /// <include file='doc\ContainerControl.uex' path='docs/doc[@for="ContainerControl.Select"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override void Select(bool directed, bool forward)
        {
            bool correctParentActiveControl = true;

            if (ParentInternal != null)
            {
                IContainerControl c = ParentInternal.GetContainerControlInternal();
                if (c != null)
                {
                    c.ActiveControl            = this;
                    correctParentActiveControl = (c.ActiveControl == this);
                }
            }
            if (directed && correctParentActiveControl)
            {
                SelectNextControl(null, forward, true, true, false);
            }
        }