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
- 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
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 System.Windows.Forms.Form.Load event handler.
public static void CenterOnParent(this Form form)
  Parameters
formForm
Remarks
This method is an alternative to System.Windows.Forms.FormStartPosition.CenterParent which only works with System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window) and not System.Windows.Forms.Form.Show(System.Windows.Forms.IWin32Window).
EnableWindowDrag(Control)
Configures a control to move the entire window when clicked and dragged.
public static void EnableWindowDrag(this Control control)
  Parameters
controlControl
HandleTouchMessage(ref Message, object?, EventHandler<TouchEventArgs>?, EventHandler<TouchEventArgs>?, EventHandler<TouchEventArgs>?)
Handles touch-related System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message) System.Windows.Forms.Messages.
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
- 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
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.
public static void SetForegroundWindow(this Form form)
  Parameters
formForm