Table of Contents

Class FocusStateHelper

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Helper class for managing focus state updates across controls. Eliminates 100% identical SetFocus boilerplate from 8+ simple controls.

public static class FocusStateHelper
Inheritance
FocusStateHelper
Inherited Members

Methods

HandleSetFocus(IWindowControl, ref bool, bool, FocusReason, EventHandler?, EventHandler?, bool)

Handles focus state changes for controls with standard focus behavior. Use this for simple controls (Button, Checkbox, etc.) that don't need custom focus logic. DO NOT use for complex controls (TreeControl, ListControl) that have custom focus handling.

public static void HandleSetFocus(IWindowControl control, ref bool hasFocusField, bool focus, FocusReason reason, EventHandler? gotFocusEvent, EventHandler? lostFocusEvent, bool invalidate = true)

Parameters

control IWindowControl

The control receiving the focus change

hasFocusField bool

Reference to the control's _hasFocus field

focus bool

True to give focus, false to remove focus

reason FocusReason

Reason for the focus change

gotFocusEvent EventHandler

The control's GotFocus event to invoke

lostFocusEvent EventHandler

The control's LostFocus event to invoke

invalidate bool

Whether to invalidate the container after focus change