Skip to content

Button

The Button widget is a focusable, clickable button with support for multiple visual styles including standard, rounded, outline, and gradient.

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.

The button text.

button.Text = "Click Me";

The visual style of the button:

  • Standard: Standard button with borders
  • Rounded: Button with rounded corners
  • Outline: Outlined button with transparent fill
  • Gradient: Button with gradient background
button.Style = ButtonStyle.Rounded;
  • PressedBackgroundColor: Background when pressed
  • PressedForegroundColor: Text color when pressed
  • FocusedBackgroundColor: Background when focused
  • FocusedForegroundColor: Text color when focused
  • BorderColor: Border color
  • GradientStartColor: Start color of gradient
  • GradientEndColor: End color of gradient
  • PressedGradientStartColor: Start color when pressed
  • PressedGradientEndColor: End color when pressed

Raised when the button is clicked.

button.Click += () =>
{
Console.WriteLine("Button clicked!");
};

Raised when the button is pressed down.

button.Pressed += () =>
{
// Button is being pressed
};

Raised when the button is released.

button.Released += () =>
{
// Button was released
};

Programmatically triggers the button click.

button.PerformClick();
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!");
};
  • Enter or Space: Activates the button
  • Tab: Navigate to next focusable widget