Show / Hide Table of Contents

Class WinFormsUtils

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

Inheritance
Object
WinFormsUtils
Namespace: NanoByte.Common.Native
Assembly: NanoByte.Common.WinForms.dll
Syntax
public static class WinFormsUtils : Object

Properties

AppIdle

Determines whether this application is currently idle.

Declaration
public static bool AppIdle { get; }
Property Value
Type Description
Boolean

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.

Declaration
public static float CaretBlinkTime { get; }
Property Value
Type Description
Single

Methods

AddShieldIcon(Button)

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

Declaration
public static void AddShieldIcon(this Button button)
Parameters
Type Name Description
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.

Declaration
public static void CenterOnParent(this Form form)
Parameters
Type Name Description
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.

Declaration
public static void EnableWindowDrag(this Control control)
Parameters
Type Name Description
Control control

HandleTouchMessage(ref Message, Object, EventHandler<TouchEventArgs>, EventHandler<TouchEventArgs>, EventHandler<TouchEventArgs>)

Handles touch-related WndProc(Message) Messages.

Declaration
public static void HandleTouchMessage(ref Message m, object sender, EventHandler<TouchEventArgs> onTouchDown, EventHandler<TouchEventArgs> onTouchMove, EventHandler<TouchEventArgs> onTouchUp)
Parameters
Type Name Description
Message m

The message to handle.

Object sender

The object to send possible events from.

EventHandler<TouchEventArgs> onTouchDown

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

EventHandler<TouchEventArgs> onTouchMove

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

EventHandler<TouchEventArgs> onTouchUp

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

IsKeyDown(Keys)

Determines whether key is pressed right now.

Declaration
public static bool IsKeyDown(Keys key)
Parameters
Type Name Description
Keys key
Returns
Type Description
Boolean
Remarks

Will always return false on non-Windows OSes.

RegisterTouchWindow(Control)

Registers a control as a receiver for touch events.

Declaration
public static void RegisterTouchWindow(Control control)
Parameters
Type Name Description
Control control

The control to register.

ReleaseCapture()

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

Declaration
public static bool ReleaseCapture()
Returns
Type Description
Boolean

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.

Declaration
public static IntPtr SetCapture(IntPtr handle)
Parameters
Type Name Description
IntPtr handle

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

Returns
Type Description
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.

Declaration
public static void SetForegroundWindow(this Form form)
Parameters
Type Name Description
Form form
In This Article
Back to top Copyright Bastian Eicher