Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Control.Handle Property

Gets the window handle that the control is bound to.

[Visual Basic]
Public Overridable ReadOnly Property Handle As IntPtr  Implements _
public virtual IntPtr Handle {get;}
public: __property virtual IntPtr get_Handle();
public function get Handle() : IntPtr;

Property Value

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




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.


[Visual Basic, C#] The following code example demonstrates using the DrawFocusRectangle method 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-handling methods.

[Visual Basic] 
' This method draws a focus rectangle on Button2 using the 
' handle and client rectangle of Button2.
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(Button2.Handle), _
End Sub

// 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)

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | CreateHandle | RecreateHandle | IsHandleCreated

© 2015 Microsoft