This document presents the API for Slice.NET Library

ScreenManager

public static class ScreenManager

Defines a set of methods for managing windows on different screens.

Enums

Properties

Functions

Enums

DisplayConfigTopology

enum DisplayConfigTopology

represents different display modes

ScreenAlignment

enum ScreenAlignment

represents different screen alignments

Example:
ScreenManager.SendToSecondary(myWindow, ScreenAlignment.Center | ScreenAlignment.Right);

Properties

SecondaryScreen

static Screen SecondaryScreen { get; }

will return the first screen which is not a primary screen or null if there is only one screen. this will work assuming the first screen that is not the primary screen is the second screen. works only on extended mode

PrimaryScreen

static Screen PrimaryScreen { get; }

will return the primary screen

CurrentTopology

static DisplayConfigTopology CurrentTopology { get; set; }

DisplayConfigTopology of current state

Example:
ScreenManager.CurrentTopology = ScreenManager.DisplayConfigTopology.External;

NumberOfDisplays

static uint NumberOfDisplays

The number of displays, even on clone or internal/external

Functions

SendToPrimary()

static bool SendToPrimary(Window window, ScreenAlignment align)
static bool SendToPrimary(Window window, int offsetX = 0, int offsetY = 0)
static bool SendToPrimary(IntPtr hwnd, ScreenAlignment align)
static bool SendToPrimary(IntPtr hwnd, int offsetX = 0, int offsetY = 0)

Sends a window to the primary screen

Parameters:
Window window/IntPtr hwnd
to send to the primary screen
ScreenAlignment align / int offsetX+offsetY
Screen alignment / offset
Return value

indicates success and failure

Example:
ScreenManager.SendToPrimary(myWindow, ScreenAlignment.Center | ScreenAlignment.Right);

SendToSecondary()

static bool SendToSecondary(Window window, ScreenAlignment align)
static bool SendToSecondary(Window window, int offsetX = 0, int offsetY = 0x)
static bool SendToSecondary(IntPtr hwnd, ScreenAlignment align)
static bool SendToSecondary(IntPtr hwnd, int offsetX = 0, int offsetY = 0)

Sends a window to the secondary screen

Parameters:
Window window/IntPtr hwnd
to send to the secondary screen
ScreenAlignment align / int offsetX+offsetY
Screen alignment / offset
Return value

indicates success and failure

Example:
ScreenManager.SendToSecondary(myWindow, ScreenAlignment.Center | ScreenAlignment.Right);

SwapScreen()

static bool SwapScreen(Window window, ScreenAlignment align)
static bool SwapScreen(Window window, int offsetX = 0, int offsetY = 0)
static bool SwapScreen(IntPtr hwnd, int offsetX = 0, int offsetY = 0)
static bool SwapScreen(IntPtr hwnd, ScreenAlignment align)

Sends a window to from primary screen to secondary or from secondary screen to primary screen.

Parameters:
Window window/IntPtr hwnd
window/window handle to send
ScreenAlignment align / int offsetX+offsetY
Screen alignment / offset
Return value

indicates success and failure. failure will denote when there aren't enough displays or the current screen topology is not extend and the extend mark is set to false

Example:
ScreenManager.SwapScreen(myWindow, ScreenAlignment.Bottom);

SendToScreen()

static bool SendToScreen(Window window, Screen screen, ScreenAlignment align)
static bool SendToScreen(Window window, Screen screen, int offsetX = 0, int offsetY = 0)
static bool SendToScreen(IntPtr hwnd, Screen screen, ScreenAlignment align)
static bool SendToScreen(IntPtr hwnd, Screen screen, int offsetX = 0, int offsetY = 0)

Sends a window to a screen.

Parameters:
Window window/IntPtr hwnd
window/window handle to send
Screen screen
to send to
ScreenAlignment align / int offsetX+offsetY
Screen alignment / offset
Return value

indicates success and failure.

Example:
ScreenManager.SendToScreen(myWindow, ScreenManager.SecondaryScreen, ScreenAlignment.Left);

ExtendScreens()

xstatic bool ExtendScreens()

Changes CurrentTopology to DisplayConfigTopology.Extend

Return value

indicates success and failure.

CloneScreens()

static bool CloneScreens()

Changes CurrentTopology to DisplayConfigTopology.Clone

Return value

indicates success and failure.

SetInternal()

static bool SetInternal()

Changes CurrentTopology to DisplayConfigTopology.Internal

Return value

indicates success and failure.

SetExternal()

static bool SetExternal()

Changes CurrentTopology to DisplayConfigTopology.External

Return value

indicates success and failure.

SendProgramsMainWindowToScreen()

static bool SendProgramsMainWindowToScreen(string progName, Screen screen, ScreenAlignment align)

Sends the main window of a program to screen

Parameters:
string progName
The name of the program
Screen screen
Screen to send the window to
ScreenAlignment align
alignment on screen
Return value

bool to indicate success or failure

SendProgramsWindowsToScreen()

static bool SendProgramsWindowsToScreen(string progName, Screen screen, ScreenAlignment align)

Sends all window of a program to a screen

Parameters:
string progName
The name of the program
Screen screen
Screen to send the window to
ScreenAlignment align
alignment on screen
Return value

bool to indicate success or failure

Example:
ScreenManager.SendProgramsWindowsToScreen("chrome", ScreenManager.SecondaryScreen, ScreenAlignment.Center);

getProcessWindowByName()

static IntPtr[] getProcessWindowByName(string proccessName)

Returns an array of window handles of all processes with the name [processName]

Parameters:
string processName
The name of the process
Return values

an array of window handles of all processes with the name [processName]

getScreenFromWindow()

static Screen getScreenFromWindow(Window window)
static Screen getScreenFromWindow(IntPtr hwnd)

Retrieves a Screen for the display that contains the largest portion of the window

Parameters:
Window window
to get screen from
Return values

The Screen for the display that contains the largest portion of the window

getWindowHandlesFromScreen()

static IntPtr[] getWindowHandlesFromScreen(Screen screen)

returns an array of window handles in a given screen

Parameters:
Screen screen
A screen
Return value

an array of window handles in given screen

getWindowHandlesFromProgramName()

static IntPtr[] getWindowHandlesFromProgramName(string progName))

returns an array of window handles associated with a program name

Parameters:
String progName
program name
Return value

an array of window handles associated with a program name

AlignmentToOffset()

static Point? AlignmentToOffset(Window window, Screen screen, ScreenAlignment alignment)
static Point? AlignmentToOffset(IntPtr hwnd, Screen screen, ScreenAlignment alignment)

Converts ScreenAlignment to Offset. alignment is depend on the window and the screen

Parameters:
Window window/IntPtr hwnd
WPF Window/window handle
Screen screen
Screen
ScreenAlignment align
alignment on screen
Return value

Point? - the offset or null in case of a problem

geDPI()

public static Point getDPI()

Returns the current dpi ((96.0,96.0) is default)

geDPIRatio()

public static Point getDPIRatio()

Returns the current dpi ratio ((96.0, 96.0) will be (1.0,1.0))

DSLEvents

public class DSLEvents : IDisposable

DSLEvents contains a single event (SecondaryScreenAvailableChanged) you can subscribe to, which is raised when the secondary screen becomes available or not available

Constructor and Dispose

Events

Event Args

DSLEvents()

public DSLEvents()

Subscribed to system's DisplaySettingsChanged. DisplaySettingsChanged is a static event so it must be detached at the end of use.

Dispose()

public void Dispose()

Detaches from system's DisplaySettingsChanged

SecondaryScreenAvailableChanged

public event EventHandler SecondaryScreenAvailableChanged

Notifies when the secondary screen's availability is changed.
In order to use this event to move the window to a different screen you should use DelayedActionOnWindow.
Subscribes to DisplaySettingsChanged which is a static event and therefore must be detached.

Example:
events.SecondaryScreenAvailableChanged += ((sender, e) =>
{
	if (e.isAvailable)
		new DelayedActionOnWindow(this,
			() => this.SendToSecondary(ScreenManager.ScreenAlignment.Center | ScreenManager.ScreenAlignment.Left)).Invoke();
});

SAvailableEventArgs

public class SAvailableEventArgs

Event arguments for SecondaryScreenAvailableChanged event

contains:
public bool isAvailable { get; private set; }

DSLExtensions

public static class DSLExtensions

Extensions for WPF windows

Functions

DelayedActionOnWindow

public class DelayedActionOnWindow

will invoke [action] in [window]'s thread when the application will be idle. useful when wanting to move a window from one screen to another screen when subscribing to DSLEvents.SecondaryScreenAvailableChanged event.

Example

Constructor

Methods

DelayedActionOnWindow()

public DelayedActionOnWindow(Window window, int delay, Action action)

creates an instance that can be invoked using Invoke() method which will invoke [action] in [window]'s thread when the application will be idle. useful when wanting to move a window from one screen to another screen when subscribing to DSLEvents.SecondaryScreenAvailableChanged event.

Parameters:
window :: Window
to get screen from
action :: Action
action to invoke

Invoke()

void Invoke()

Invokes the delayed action