Control.Handle Property

Definition

Gets the window handle that the control is bound to.

C#
[System.ComponentModel.Browsable(false)]
public IntPtr Handle { get; }

Property Value

IntPtr

An IntPtr that contains the window handle (HWND) of the control.

Implements

Attributes

Examples

The following code example demonstrates using the ControlPaint.DrawFocusRectangle and the Handle property. To run the example paste the following code in a form. Add two buttons named Button1 and Button2 to the form and ensure all events are connected to their event handlers.

C#
// This method draws a focus rectangle on Button2 using the 
// handle and client rectangle of Button2.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(Button2.Handle), 
        Button2.ClientRectangle);
}

Remarks

The value of the Handle property is a Windows HWND. If the handle has not yet been created, referencing this property will force the handle to be created.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also