PowerArgs.Cli.FocusManager.TryMoveFocus C# (CSharp) Method

TryMoveFocus() public method

Tries to move the focus forward or backwards
public TryMoveFocus ( bool forward = true ) : bool
forward bool If true then the manager will try to move forwards, otherwise backwards
return bool
        public bool TryMoveFocus(bool forward = true)
        {
            if (focusStack.Peek().Controls.Count == 0)
            {
                return false;
            }

            int initialPosition = focusStack.Peek().FocusIndex;

            do
            {
                bool wrapped = CycleFocusIndex(forward);
                var nextControl = focusStack.Peek().Controls[focusStack.Peek().FocusIndex];
                if(nextControl.CanFocus)
                {
                    return TrySetFocus(nextControl);
                }

                if (wrapped && initialPosition < 0) break;
            }
            while (focusStack.Peek().FocusIndex != initialPosition);

            return false;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override Task Start()
        {
            QueueAction(() =>
            {
                if (_current != null)
                {
                    throw new NotSupportedException("An application is already running on this thread.");
                }
                // ensures that the current app is set on the message pump thread
                _current = this;
            });

            if (SetFocusOnStart)
            {
                QueueAction(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            Paint();

            Task pumpTask = base.Start();

            var cleanupTask = pumpTask.ContinueWith((t) =>
            {
                ExitInternal();
            });

            return(cleanupTask);
        }
All Usage Examples Of PowerArgs.Cli.FocusManager::TryMoveFocus