Skip to content
github-actions[bot] edited this page Oct 31, 2025 · 1 revision

Access display and screen information for responsive layouts.

Overview

The Electron.Screen API provides access to screen and display information, including screen size, display metrics, cursor position, and multi-monitor configurations. This is essential for creating responsive applications that adapt to different screen configurations.

Methods

🧊 Task<Display[]> GetAllDisplaysAsync()

Gets information about all available displays.

Returns:

An array of displays that are currently available.

🧊 Task<Point> GetCursorScreenPointAsync()

Gets the current position of the mouse cursor on screen.

Returns:

The current absolute position of the mouse pointer.

🧊 Task<Display> GetDisplayMatchingAsync(Rectangle rectangle)

Gets the display that most closely intersects the provided bounds.

Parameters:

  • rectangle - The rectangle to find the matching display for

Returns:

The display that most closely intersects the provided bounds.

🧊 Task<Display> GetDisplayNearestPointAsync(Point point)

Gets the display that is closest to the specified point.

Parameters:

  • point - The point to find the nearest display for

Returns:

The display nearest the specified point.

🧊 Task<int> GetMenuBarHeightAsync()

macOS: The height of the menu bar in pixels.

Returns:

The height of the menu bar in pixels.

🧊 Task<Display> GetPrimaryDisplayAsync()

Gets information about the primary display (main screen).

Returns:

The primary display.

Events

OnDisplayAdded

Emitted when a new Display has been added.

OnDisplayMetricsChanged

Emitted when one or more metrics change in a display. The changedMetrics is an array of strings that describe the changes. Possible changes are bounds, workArea, scaleFactor and rotation.

OnDisplayRemoved

Emitted when oldDisplay has been removed.

Usage Examples

Display Information

// Get primary displayvarprimaryDisplay=awaitElectron.Screen.GetPrimaryDisplayAsync();Console.WriteLine($"Primary display: {primaryDisplay.Size.Width}x{primaryDisplay.Size.Height}");// Get all displaysvardisplays=awaitElectron.Screen.GetAllDisplaysAsync();Console.WriteLine($"Available displays: {displays.Length}");// Get display near cursorvarcursorPoint=awaitElectron.Screen.GetCursorScreenPointAsync();varnearestDisplay=awaitElectron.Screen.GetDisplayNearestPointAsync(cursorPoint);Console.WriteLine($"Nearest display scale factor: {nearestDisplay.ScaleFactor}");

Multi-Monitor Setup

// Get all displays for multi-monitor setupvardisplays=awaitElectron.Screen.GetAllDisplaysAsync();foreach(vardisplayindisplays){Console.WriteLine($"Display {display.Id}:");Console.WriteLine($" Size: {display.Size.Width}x{display.Size.Height}");Console.WriteLine($" Position: {display.Bounds.X},{display.Bounds.Y}");Console.WriteLine($" Scale Factor: {display.ScaleFactor}");Console.WriteLine($" Work Area: {display.WorkArea.Width}x{display.WorkArea.Height}");}

Responsive Window Placement

// Create window on appropriate displayvardisplays=awaitElectron.Screen.GetAllDisplaysAsync();vartargetDisplay=displays.FirstOrDefault(d =>d.Bounds.X>0)??displays.First();varwindowOptions=newBrowserWindowOptions{Width=Math.Min(1200,targetDisplay.WorkArea.Width),Height=Math.Min(800,targetDisplay.WorkArea.Height),X=targetDisplay.WorkArea.X+(targetDisplay.WorkArea.Width-1200)/2,Y=targetDisplay.WorkArea.Y+(targetDisplay.WorkArea.Height-800)/2};varwindow=awaitElectron.WindowManager.CreateWindowAsync(windowOptions);

Display Change Monitoring

// Monitor display changesElectron.Screen.OnDisplayAdded+=(display)=>{Console.WriteLine($"Display added: {display.Id}");UpdateWindowPositions();};Electron.Screen.OnDisplayRemoved+=(display)=>{Console.WriteLine($"Display removed: {display.Id}");UpdateWindowPositions();};Electron.Screen.OnDisplayMetricsChanged+=(display,metrics)=>{Console.WriteLine($"Display {display.Id} metrics changed: {string.Join(", ",metrics)}");UpdateWindowPositions();};voidUpdateWindowPositions(){// Recalculate window positions based on current displays}

macOS Menu Bar Height

// Account for menu bar height on macOSif(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)){varmenuBarHeight=awaitElectron.Screen.GetMenuBarHeightAsync();varwindowOptions=newBrowserWindowOptions{Y=menuBarHeight,// Position below menu barTitleBarStyle=TitleBarStyle.Hidden// Hide title bar for custom look};}

Related APIs

Additional Resources

Clone this wiki locally