Table of Contents

Class ControlExtensions

Namespace
NanoByte.Common.Controls
Assembly
NanoByte.Common.WinForms.dll

Provides extension methods for Controls.

public static class ControlExtensions
Inheritance
object
ControlExtensions

Methods

ApplyScale(Size, ContainerControl)

Scales a Size according to the current auto-scaling factor.

public static Size ApplyScale(this Size size, ContainerControl control)

Parameters

size Size

The size to scale.

control ContainerControl

The control to get the scaling factor from.

Returns

Size

BeginInvoke(Control, Action)

Executes the given action on the thread that owns this control and returns immediately.

public static void BeginInvoke(this Control control, Action action)

Parameters

control Control
action Action

DisableSorting(DataGridView)

Disables sorting for all current and future columns of a data grid.

public static void DisableSorting(this DataGridView dataGrid)

Parameters

dataGrid DataGridView

Remarks

Use this for grids bound to data sources that do not support sorting. Otherwise, the F3 key tries to sort anyway and throws an exception.

GetScaleFactor(ContainerControl)

Returns the current auto-scaling factor.

public static SizeF GetScaleFactor(this ContainerControl control)

Parameters

control ContainerControl

Returns

SizeF

Remarks

Assumes the default AutoScaleDimensions of 6, 13 for Font or 96, 96 for Dpi. Unlike AutoScaleFactor this will retain the correct factor even after PerformAutoScale() has run.

Invoke(Control, Action)

Executes the given action on the thread that owns this control and blocks until it is complete.

public static void Invoke(this Control control, Action action)

Parameters

control Control
action Action

Invoke<T>(Control, Func<T>)

Executes the given action on the thread that owns this control and blocks until it is complete.

public static T Invoke<T>(this Control control, Func<T> action)

Parameters

control Control
action Func<T>

Returns

T

The return value of the action.

Type Parameters

T