In This Article

ControlExtensions Class

Provides extension methods for the type Control

public static class ControlExtensions
Inheritance:
object object

Methods

FindAncestorOfType<T>(Control?, bool)

Finds the first ancestor of the given type in the control hierarchy.

public static T? FindAncestorOfType<T>(this Control? control, bool includeSelf = false) where T : class
Type Parameters:
T -

The type of ancestor to find.

Parameter Type Description
control Control

The control to examine.

includeSelf bool

Indicates if the given control should be included in the search.

Returns

T:

The first ancestor of the given type, or null if a match was not found.

See Also

FindCommonAncestor(Control?, Control?)

Tries to find the closest ancestor in the control hierarchy that is common between two controls.

public static Control? FindCommonAncestor(this Control? control, Control? target)
Parameter Type Description
control Control

The first control to examine.

target Control

The second control to examine.

Returns

Control:

The closest ancestor in the control hierarchy that is common between two controls.

See Also

FindDescendantOfType<T>(Control?, bool)

Finds the first descendant of the given type in the control hierarchy.

public static T? FindDescendantOfType<T>(this Control? control, bool includeSelf = false) where T : class
Type Parameters:
T -

The type of descendant to find.

Parameter Type Description
control Control

The control to examine.

includeSelf bool

Indicates if the given control should be included in the search.

Returns

T:

The first descendant of the given type, or null if a match was not found.

See Also

GetAncestors(Control)

Enumerates the ancestors of a control in the control hierarchy.

public static IEnumerable<Control> GetAncestors(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

IEnumerable<Control>

See Also

GetChildren(Control)

Enumerates the children of a control in the control hierarchy.

public static IEnumerable<Control> GetChildren(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

IEnumerable<Control>

See Also

GetDescendants(Control)

Enumerates the descendants of a control in the control hierarchy.

public static IEnumerable<Control> GetDescendants(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

IEnumerable<Control>

See Also

GetParent(Control)

Returns the parent of a control in the control hierarchy.

public static Control? GetParent(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

Control:

The parent, or null if the control does not have a parent.

See Also

GetParent<T>(Control)

Returns the parent of a control in the control hierarchy.

public static T? GetParent<T>(this Control control) where T : class
Type Parameters:
T -

The type of the parent.

Parameter Type Description
control Control

The control to examine.

Returns

T:

The parent, or null if the control does not have a parent or its parent is not of the type T.

See Also

GetSelfAndAncestors(Control)

Enumerates a control and its ancestors in the control hierarchy.

public static IEnumerable<Control> GetSelfAndAncestors(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

IEnumerable<Control>

See Also

GetSelfAndDescendants(Control)

Enumerates a control and its descendants in the control hierarchy.

public static IEnumerable<Control> GetSelfAndDescendants(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

IEnumerable<Control>

See Also

GetSiblings(Control)

Enumerates the siblings of a control in the control hierarchy.

public static IEnumerable<Control> GetSiblings(this Control control)
Parameter Type Description
control Control

The control to examine.

Returns

IEnumerable<Control>

See Also

IsAncestorOf(Control?, ILogicalTreeNode?)

Tests whether a control is a logical ancestor of an object in the logical tree.

public static bool IsAncestorOf(this Control? control, ILogicalTreeNode? target)
Parameter Type Description
control Control

The control to examine.

target ILogicalTreeNode

The potential descendant.

Returns

bool:

true if the control is a logical ancestor of target; otherwise, false.

See Also

IsAncestorOf(Control?, Control?)

Tests whether a control is an ancestor of another control in the control hierarchy.

public static bool IsAncestorOf(this Control? control, Control? target)
Parameter Type Description
control Control

The control to examine.

target Control

The potential descendant.

Returns

bool:

true if the control is an ancestor of target; otherwise, false.

See Also

Inherited Members

See Also