Recursive AI

Add a tooltip to a C# desktop button

OneApp is a free, open-source framework for apps in .NET whose UI is HTML and CSS, drawn natively with no web view on Windows, macOS, Linux, iOS and Android, and run in the browser, from Recursive AI. MIT or Apache-2.0, no native DLLs to ship.

Wrap the button in Tooltip and set DelayMs for hover. OneApp runs on Linux, Windows, and macOS on Apple silicon.

Terminal
dotnet add package RecursiveAI.OneApp.Kit
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

HTML
<!-- Export: handler in ExportPage.cs. -->
<Tooltip Id="export-help" DelayMs="500"
  Text="Downloads a CSV of the current report.">
  <Button Id="export"
    AriaDescribedBy="export-help"
    OnClick="{Export}">Export report</Button>
</Tooltip>

The example is the full program below: unzip it and dotnet run.

Hover over Export report for half a second, or press Tab to focus it.

Full program

OneApp hosts the window, OneApp.Kit supplies the controls, and OneUI compiles the .html component.

The zip contains the three files below and Demo.csproj. To make the project by hand, create a .NET 10 console app and install the packages above. The example’s project references are:

XML
<PackageReference Include="RecursiveAI.OneApp" Version="1.1.1" />
<PackageReference Include="RecursiveAI.OneApp.Kit" Version="1.1.1" />
<PackageReference Include="RecursiveAI.OneUI" Version="1.1.0" />

OneUI compiles ExportPage.html into the other half of the partial class in ExportPage.cs. Save these files beside the project file.

ExportPage.html:

HTML
<Theme>
  <main style="padding: 24px">
    <h2 style="margin-bottom: 36px">Report</h2>
    <Tooltip Id="export-help" DelayMs="500"
             Text="Downloads a CSV of the current report.">
      <Button Id="export" AriaDescribedBy="export-help"
              OnClick="{Export}">Export report</Button>
    </Tooltip>
  </main>
</Theme>

ExportPage.cs:

C#
public partial class ExportPage
{
    private static void Export() => Console.WriteLine("Export requested (demo only).");
}

Program.cs opens the native window:

C#
using OneApp;
 
using var host = AppHost.Create(new AppOptions(new ExportPage())
{
    Title = "Export",
    Width = 420,
    Height = 205,
});
host.Run();

The tooltip shows this text in the window:

Text
Downloads a CSV of the current report.

Move the pointer away, move focus away, or press Escape while the button has focus to hide the tooltip. Activating the button prints Export requested (demo only). in the terminal; the example doesn’t write a CSV.

If the hint appears visually but the button has no description, check that AriaDescribedBy exactly matches the tooltip’s Id.

Add a tooltip to a C# desktop button: example window

Variations

To prefer the space below the button, add Side to the opening tag in ExportPage.html:

HTML
<Tooltip Id="export-help" DelayMs="500"
  Side="{OneApp.Kit.OverlaySide.Bottom}"
  Text="Downloads a CSV of the current report.">

The short answer

Put the Button inside Tooltip. Set Text to the hint, DelayMs to the hover delay, and give the tooltip an Id. Put the same ID in the button’s AriaDescribedBy. That connects the hint as a description without replacing the button’s name.

How do I display a tooltip on a button?

The button goes in the tooltip’s default slot: there’s no separate trigger declaration. In the example, Export report names the action and the tooltip adds the file format and which report is exported. Keep the label meaningful without the hint, and put instructions that are required to complete a task in visible text instead.

What is the difference between a tooltip and hover?

Hover is one way to show a tooltip. It isn’t the only one: DelayMs="500" waits for the pointer to rest on the button, but moving keyboard focus to the button shows the hint immediately. Pressing Escape with focus on the button dismisses the hint without moving focus. Unlike a popover, the tooltip contains text, not controls the user needs to reach.

All oneapp recipes