ConsoleButtons 3.0.0

dotnet add package ConsoleButtons --version 3.0.0
                    
NuGet\Install-Package ConsoleButtons -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConsoleButtons" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConsoleButtons" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ConsoleButtons" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConsoleButtons --version 3.0.0
                    
#r "nuget: ConsoleButtons, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConsoleButtons@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConsoleButtons&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ConsoleButtons&version=3.0.0
                    
Install as a Cake Tool

<h1 align="center" id="title">Console Buttons</h1>

<p align="center"><img src="https://socialify.git.ci/wTechnoo/ConsoleButtons/image?description=1&font=Source%20Code%20Pro&language=1&logo=https%3A%2F%2Fcdn.discordapp.com%2Fattachments%2F602356897726857216%2F922317460802273310%2FCBLogo_4.png&owner=1&pattern=Diagonal%20Stripes&stargazers=1&theme=Dark" alt="project-image"></p>

<p align="center" id="description">Clickable UI for C# Console</p> <p align="center" id="description">Buttons, checkboxes, sliders and more!</p>

<h2 align="center">⚠️ Warning</h2> <p align="center" id="description">Console buttons will only work when launched through the built .EXE on RELEASE mode</p>

<h2 align="center">✔️ Changes (3.0.0) — automatic sizing</h2> <p align="center" id="description">Colliders are now measured, not hand-tuned. Everything works in console cells instead of pixels.</p> <p align="center" id="description">1. <b>No more width/height arguments.</b> A component's collider is measured from exactly what it paints, so it can never drift away from its text</p> <p align="center" id="description">2. <b>No more hardcoded font sizes.</b> The character cell is measured from the window's client area, so it stays correct across font changes, DPI scaling and resizes</p> <p align="center" id="description">3. Wide text is measured properly — CJK and emoji paint two cells each, which <code>string.Length</code> gets wrong</p> <p align="center" id="description">4. Multi-line text is supported: every line is placed at the component's X, and height comes from the line count</p> <p align="center" id="description">5. Hover events are edge-triggered, so <code>OnHoverStop</code> no longer fires every frame on every component</p>

<h2 align="center">⚠️ Upgrading from 2.x</h2> <p align="center" id="description">1. <code>new Button(text, x, y, w, h)</code> still compiles but the w and h are ignored — drop them</p> <p align="center" id="description">2. <code>UIComponent</code> is now abstract; custom components implement <code>protected override string Render()</code> and get their collider for free</p> <p align="center" id="description">3. <code>AABB</code> is in cells now, not pixels. <code>UICollision</code> takes a column and a row</p> <p align="center" id="description">4. A slider's <code>[</code> now sits on the X you give it rather than one column to its left (so x: 0 no longer throws)</p>

<h2 align="center">❔ To be worked on</h2> <p align="center" id="description">1. Adding a way to the user to use their own/downloaded console packages (such as Colorful.Console or any other color package)</p>

<h2 align="center"> 📌<a href="https://www.nuget.org/packages/ConsoleButtons/2.4.0">Package</a></h2> <p align="center" id="description">Download the package through nugget or build it yourself!</p>

<h2 align="center">⌨️ Example Usage</h2>

static void Main(string[] args)
{
    UIManager manager = new UIManager();
    
    //Button constructor order (text string, X and Y). The collider is measured from the text.
    Button button = new Button("Sign Up", 0, 0);
    button.OnHoverOver += () => { button.WriteWithColor(ConsoleColor.Gray); };
    button.OnHoverStop += () => { button.WriteWithNoColor(); };
    button.OnClick += () => { button.WriteWithColor(ConsoleColor.Red); Thread.Sleep(50); };
    button.OnHold += () => { button.WriteWithColor(ConsoleColor.Red); };

    //Checkbox constructor order (text string, marked checkbox char, is initialized as checked, collide with text, X and Y)
    //Without the "collide with text" argument only the [ ] box is clickable.
    CheckBox checkBox = new CheckBox("Checkbox", 'X', false, true, 0, 2);
    checkBox.OnHoverOver += () => { checkBox.WriteWithColor(ConsoleColor.Gray); };
    checkBox.OnHoverStop += () => { checkBox.WriteWithNoColor(); };
    checkBox.OnClick += () => { checkBox.WriteWithColor(ConsoleColor.Cyan); Thread.Sleep(50); };
    checkBox.OnHold += () => { checkBox.WriteWithColor(ConsoleColor.Red); };

    //Slider constructor order (initial value, max value, slider size, convert to int, filled char, unfilled char, X and Y)
    //"size" is the number of cells between the brackets, so this one is 12 cells wide in total.
    Slider slider = new Slider(0, 10, 10, false, '█', ' ', 5, 5);
    slider.OnHoverOver += () => { slider.WriteWithColor(ConsoleColor.Gray); };
    slider.OnHoverStop += () => { slider.WriteWithNoColor(); };
    slider.OnHold += () => { slider.WriteWithColor(ConsoleColor.Red); };

    manager.AddToComponents(button);
    manager.AddToComponents(checkBox);
    manager.AddToComponents(slider);

    while (true)
    {
        manager.Update();
    }
}

<h2 align="center">🧩 Custom components</h2> <p align="center" id="description">Override <code>Render()</code> with whatever the component paints. That single method drives both the drawing and the collider, so they stay in sync on their own.</p>

public class Label : UIComponent
{
    string _text;

    public Label(string text, int x, int y)
    {
        _text = text;
        ConsolePosition = new Point(x, y);
    }

    protected override string Render() => $"< {_text} >";

    //Optional: make only part of the render clickable. Defaults to all of it.
    //protected override string HitArea() => _text;
}
Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7.2

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 164 8/12/2026
2.4.0 748 12/24/2021
2.3.0 572 10/2/2021
2.2.5 508 9/28/2021
2.2.3 546 9/28/2021
2.2.2 545 9/28/2021
2.0.0 758 9/27/2021 2.0.0 is deprecated because it is no longer maintained.