private bool TabToNextControl(Control focus, bool forward) { // Start searching from the current focus control Control next = focus; // If only allow focus on a control within the page instance, so // setting to null will force the GetNextControl to get the first // child control of the page. if (!_page.Contains(next)) { next = null; } // Have we wrapped around the end yet? bool wrapped = false; do { // Find the next control in sequence next = _page.GetNextControl(next, forward); // If no more controls found, then finished if (next == null) { // If already wrapped around end of list then must be finished if (wrapped) { return(false); } // Keep going from the start wrapped = true; } else { // Can only selected controls that are inside ourself as a container if (_page.Contains(next)) { // If the next control is allowed to become selected // and allowed to be selected because of a tab action if (next.CanSelect && next.TabStop) { // Is the next control a container control? if (next is ContainerControl) { // If the source control of the next/previous is inside the container // then we do not want to stop at the container itself as that would // just put the focus straight back into the container. So keep going. if (!next.Contains(focus)) { // We need to call the protected select method in order to have // it perform an internal select of the first/last ordered item _containerSelect.Invoke(next, new object[] { true, forward }); return(true); } } else { // Select the actual control if (!_page.ContainsFocus) { next.Focus(); } else { next.Select(); } return(true); } } } } }while (next != focus); // We always override processing of this method return(true); }