---
title: "Create an always-on-top overlay window in C#"
url: https://recursiveai.org/oneplatform/cookbook/create-always-on-top-overlay/
description: "Create a borderless, always-on-top overlay in C# with OnePlatform. Set its size and screen position, and see which desktop settings apply."
version: "1.0.0"
---

# Create an always-on-top overlay window in C#

**OnePlatform** is a free, open-source library for windows, input, clipboard, displays and gamepads in .NET from Recursive AI. MIT or Apache-2.0, no native DLLs to ship.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePlatform) · [GitHub](https://github.com/recursive-ai-oss/oneplatform-csharp) · [Docs](https://recursiveai.org/oneplatform/docs/) · [Download example (.zip)](https://recursiveai.org/oneplatform/cookbook/create-always-on-top-overlay/create-always-on-top-overlay.zip)

Set `WindowOptions.Overlay` to open a floating panel. On Linux Wayland desktops, the compositor must support the layer-shell protocol.

```shell
dotnet add package RecursiveAI.OnePlatform
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OnePlatform;

using var app = PlatformApp.Create();
var window = app.CreateWindow(new()
{
    Title = "Status overlay",
    Width = 240,
    Height = 80,
    Overlay = new OverlayOptions()
});
System.Console.WriteLine(window.Role);
while (true) app.PumpEvents(1000);
```

[The example](https://recursiveai.org/oneplatform/cookbook/create-always-on-top-overlay/create-always-on-top-overlay.zip) is the full program below: unzip it and `dotnet run`. To run only the code above, paste it into Program.cs of a new `dotnet new console` project and `dotnet run`.

The snippet opens a centered panel with no title bar. Stop it with Ctrl+C. It prints:

```text
Overlay
```

## The full program

The download keeps the panel open for five seconds, then exits. Run it from a graphical desktop session.

```csharp
using System;
using OnePlatform;

using var app = PlatformApp.Create();
var window = app.CreateWindow(new()
{
    Title = "Status overlay",
    Width = 240,
    Height = 80,
    Overlay = new OverlayOptions()
});
Console.WriteLine($"{window.Role}, frame: {window.Decoration}");

// Keep the demo visible for five seconds, then close it.
long end = Environment.TickCount64 + 5000;
while (Environment.TickCount64 < end)
    app.PumpEvents(100);
```

```text
Overlay, frame: None
```

The demo creates the window shell, not the controls or graphics inside it. If Wayland doesn’t offer layer-shell, `CreateWindow` throws `OverlayUnavailableException` unless you opt in to an ordinary-window fallback.

## Variations

To put the panel in the upper-right corner instead of the center, replace the `Overlay =` line with:

```csharp
Overlay = new OverlayOptions
{
    Anchors = OverlayAnchors.Top | OverlayAnchors.Right,
    MarginTop = 16,
    MarginRight = 16
}
```

## Related recipes

- [Create a native cross-platform window](https://recursiveai.org/oneplatform/cookbook/create-native-cross-platform-window/)
- [Handle per-monitor DPI](https://recursiveai.org/oneplatform/cookbook/handle-per-monitor-dpi/)

## The short answer

Set `WindowOptions.Overlay` when you call `PlatformApp.CreateWindow`. You get a frameless window with an overlay role, so you can place a status panel above ordinary windows without giving it a title bar or making it a child of another window. Windows uses a topmost tool window, macOS uses a native window level, Wayland uses the compositor’s overlay or top layer, and X11 asks the window manager to keep a dock window above ordinary windows. If the panel must always stay above ordinary windows, leave `FallbackToToplevel` off and handle `OverlayUnavailableException` on unsupported Wayland compositors.

## How do you make a window always stay on top?

Use an overlay when the window is a floating panel from the moment it opens. If you want a system frame and resize controls, keep an ordinary window and use the [keep-above toggle](https://recursiveai.org/oneplatform/docs/desktop-windows/). Changing an ordinary window’s stacking doesn’t give it the overlay role or edge anchors.

An overlay isn’t the same as a popup. A popup is tied to a rectangle inside a parent window, for example to put a menu under a button. An overlay is positioned on the screen, which is useful when a panel should stay in the same corner while the user switches between windows. `Anchors` selects the edges and the corresponding margins offset the panel from them. On X11 and Wayland, anchoring to opposite edges stretches the panel along that axis; for an upper-right card, anchor only the top and right, as above.

## Can a window stay on top without taking keyboard focus?

On Windows, a OnePlatform overlay is a topmost tool window placed in the primary monitor’s work area. With `OverlayKeyboard.None` (the default), clicks don’t activate the window. On macOS, an overlay with `None` never becomes the key window; Cocoa uses a native window level for its stacking and places it on the main screen. Choosing `None` is about keyboard focus, not whether mouse clicks pass through the window. On X11, the overlay’s keyboard setting is ignored, so don’t rely on it for a panel that must never take the focus.

## Why doesn’t my always-on-top overlay work on Wayland?

A OnePlatform Wayland overlay uses `zwlr_layer_shell_v1`, a protocol the compositor must offer. The compositor chooses the final size. A compositor without that protocol can still open ordinary windows, but it can’t make this kind of overlay. `FallbackToToplevel` lets you show the panel as an ordinary window when it would be more useful there than hidden. Check `Window.Role` before describing the result as always on top: the fallback reports `Toplevel`. X11 has a different mechanism: OnePlatform asks the X11 window manager to treat the window as a dock and sets `_NET_WM_STATE_ABOVE`.
