Class WinFormsUtils
Provides helper methods and API calls specific to the System.Windows.Forms UI toolkit.
public static class WinFormsUtils
- Inheritance
-
objectWinFormsUtils
Properties
AppIdle
Determines whether this application is currently idle.
public static bool AppIdle { get; }
Property Value
- bool
trueif idle,falseif 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
Methods
AddShieldIcon(Button)
Adds a UAC shield icon to a button. Does nothing if not running Windows Vista or newer.
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Native API only applies to buttons.")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static void AddShieldIcon(this Button button)
Parameters
buttonButton
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
formForm
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.
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "This method operates only on windows and not on individual controls.")]
public static void EnableWindowDrag(this Control control)
Parameters
controlControl
HandleTouchMessage(ref Message, object?, EventHandler<TouchEventArgs>?, EventHandler<TouchEventArgs>?, EventHandler<TouchEventArgs>?)
Handles touch-related WndProc(ref Message) Messages.
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static void HandleTouchMessage(ref Message m, object? sender, EventHandler<TouchEventArgs>? onTouchDown, EventHandler<TouchEventArgs>? onTouchMove, EventHandler<TouchEventArgs>? onTouchUp)
Parameters
mMessageThe message to handle.
senderobjectThe object to send possible events from.
onTouchDownEventHandler<TouchEventArgs>The event handler to call for touch down events; can be
null.onTouchMoveEventHandler<TouchEventArgs>The event handler to call for touch move events; can be
null.onTouchUpEventHandler<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
keyKeys
Returns
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
controlControlThe control to register.
ReleaseCapture()
Releases the mouse cursor after it was locked by SetCapture(IntPtr).
public static bool ReleaseCapture()
Returns
- bool
trueif successful;falseotherwise.
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
handleIntPtrThe 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.
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "This method operates only on windows and not on individual controls.")]
public static void SetForegroundWindow(this Form form)
Parameters
formForm