Table of Contents

Class WinFormsUtils

Namespace
NanoByte.Common.Native
Assembly
NanoByte.Common.WinForms.dll

Provides helper methods and API calls specific to the System.Windows.Forms UI toolkit.

public static class WinFormsUtils
Inheritance
WinFormsUtils

Properties

AppIdle

Determines whether this application is currently idle.

public static bool AppIdle { get; }

Property Value

bool

true if idle, false if handling window events.

Remarks

Will always return true on non-Windows OSes.

CaretBlinkTime

Text-box caret blink time in seconds.

public static float CaretBlinkTime { get; }

Property Value

float

Methods

AddShieldIcon(Button)

Adds a UAC shield icon to a button. Does nothing if not running Windows Vista or newer.

public static void AddShieldIcon(this Button button)

Parameters

button Button

Remarks

This is purely cosmetic. UAC elevation is a separate concern.

CenterOnParent(Form)

Centers a window on its parent/owner. Call this from the Load event handler.

public static void CenterOnParent(this Form form)

Parameters

form Form

Remarks

This method is an alternative to CenterParent which only works with ShowDialog(IWin32Window) and not Show(IWin32Window).

EnableWindowDrag(Control)

Configures a control to move the entire window when clicked and dragged.

public static void EnableWindowDrag(this Control control)

Parameters

control Control

HandleTouchMessage(ref Message, object?, EventHandler<TouchEventArgs>?, EventHandler<TouchEventArgs>?, EventHandler<TouchEventArgs>?)

Handles touch-related WndProc(ref Message)Messages.

public static void HandleTouchMessage(ref Message m, object? sender, EventHandler<TouchEventArgs>? onTouchDown, EventHandler<TouchEventArgs>? onTouchMove, EventHandler<TouchEventArgs>? onTouchUp)

Parameters

m Message

The message to handle.

sender object

The object to send possible events from.

onTouchDown EventHandler<TouchEventArgs>

The event handler to call for touch down events; can be null.

onTouchMove EventHandler<TouchEventArgs>

The event handler to call for touch move events; can be null.

onTouchUp EventHandler<TouchEventArgs>

The event handler to call for touch up events; can be null.

IsKeyDown(Keys)

Determines whether key is pressed right now.

public static bool IsKeyDown(Keys key)

Parameters

key Keys

Returns

bool

Remarks

Will always return false on non-Windows OSes.

RegisterTouchWindow(Control)

Registers a control as a receiver for touch events.

public static void RegisterTouchWindow(Control control)

Parameters

control Control

The control to register.

ReleaseCapture()

Releases the mouse cursor after it was locked by SetCapture(IntPtr).

public static bool ReleaseCapture()

Returns

bool

true if successful; false otherwise.

Remarks

Will always return false on non-Windows OSes.

SetCapture(IntPtr)

Prevents the mouse cursor from leaving a specific window.

public static IntPtr SetCapture(IntPtr handle)

Parameters

handle IntPtr

The handle to the window to lock the mouse cursor into.

Returns

IntPtr

A handle to the window that had previously captured the mouse.

Remarks

Will do nothing on non-Windows OSes.

SetForegroundWindow(Form)

Forces a window to the foreground or flashes the taskbar if another process has the focus.

public static void SetForegroundWindow(this Form form)

Parameters

form Form