Button
The Button widget is a focusable, clickable button with support for multiple visual styles including standard, rounded, outline, and gradient.
Overview
Section titled “Overview”Button is one of the most commonly used input widgets. It supports keyboard activation (Enter/Space) and provides visual feedback for focus and press states.
Properties
Section titled “Properties”Text (string)
Section titled “Text (string)”The button text.
button.Text = "Click Me";Style (ButtonStyle)
Section titled “Style (ButtonStyle)”The visual style of the button:
Standard: Standard button with bordersRounded: Button with rounded cornersOutline: Outlined button with transparent fillGradient: Button with gradient background
button.Style = ButtonStyle.Rounded;Color Properties
Section titled “Color Properties”PressedBackgroundColor: Background when pressedPressedForegroundColor: Text color when pressedFocusedBackgroundColor: Background when focusedFocusedForegroundColor: Text color when focusedBorderColor: Border color
Gradient Properties (for Gradient style)
Section titled “Gradient Properties (for Gradient style)”GradientStartColor: Start color of gradientGradientEndColor: End color of gradientPressedGradientStartColor: Start color when pressedPressedGradientEndColor: End color when pressed
Events
Section titled “Events”Raised when the button is clicked.
button.Click += () =>{ Console.WriteLine("Button clicked!");};Pressed
Section titled “Pressed”Raised when the button is pressed down.
button.Pressed += () =>{ // Button is being pressed};Released
Section titled “Released”Raised when the button is released.
button.Released += () =>{ // Button was released};Methods
Section titled “Methods”PerformClick()
Section titled “PerformClick()”Programmatically triggers the button click.
button.PerformClick();Usage Example
Section titled “Usage Example”var button = new Button("OK"){ X = 10, Y = 5, Width = 15, Height = 3, Style = ButtonStyle.Rounded, BackgroundColor = ColorHelper.FromRgb(66, 135, 245), ForegroundColor = Color.White, PressedBackgroundColor = ColorHelper.FromRgb(40, 90, 180)};
button.Click += () =>{ Console.WriteLine("OK clicked!");};Keyboard Interaction
Section titled “Keyboard Interaction”- Enter or Space: Activates the button
- Tab: Navigate to next focusable widget
Related Widgets
Section titled “Related Widgets”- TextField - For text input
- Checkbox - For boolean input
- Base Widget - Base class documentation