Ejemplo n.º 1
0
            public int CompareTo(object obj)
            {
                TabStopControl t = (TabStopControl)obj;

                if (t != null)
                {
                    return(this._c.TabIndex - t._c.TabIndex);
                }
                return(0);
            }
Ejemplo n.º 2
0
        public void HandleTab(KeyEventArgs e)
        {
            // Build list of TabStop controls in the form.
            if (tabStops == null)
            {
                tabStops = new List <TabStopControl>();
                FindTabStops(_owner.Controls, tabStops);
                tabStops.Sort();
            }

            // Find the current focussed control.
            int i = 0;

            for (int len = tabStops.Count - 1; i < len; i++)
            {
                TabStopControl t = tabStops[i];
                if (t.Control.Focused)
                {
                    break;
                }
            }

            // Find the next in the specified direction, skipping currently invisible controls
            bool forward = (e.Modifiers & Keys.Shift) == 0;
            int  dir     = forward ? 1 : -1;

            i += dir;
            Control next    = null;
            bool    wrapped = false;

            while (next == null)
            {
                if (i < 0)
                {
                    if (wrapped)
                    {
                        break;
                    }
                    i       = tabStops.Count - 1;
                    wrapped = true;
                }
                if (i >= tabStops.Count)
                {
                    if (wrapped)
                    {
                        break;
                    }
                    i       = 0;
                    wrapped = true;
                }
                TabStopControl t = tabStops[i];
                if (t.Control.Visible)
                {
                    next = t.Control;
                    break;
                }
                i += dir;
            }

            // Now focus the next control.
            if (next != null)
            {
                next.Focus();
                e.Handled = true;
            }
        }