Control.Handle 属性

获取控件绑定到的窗口句柄。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public ReadOnly Property Handle As IntPtr
用法
Dim instance As Control
Dim value As IntPtr

value = instance.Handle
public IntPtr Handle { get; }
public:
virtual property IntPtr Handle {
    IntPtr get () sealed;
}
/** @property */
public final IntPtr get_Handle ()
public final function get Handle () : IntPtr

属性值

一个 IntPtr,包含控件的窗口句柄 (HWND)。

备注

Handle 属性的值是 Windows HWND。如果句柄尚未创建,引用该属性将强制创建句柄。

示例

下面的代码示例演示如何使用 ControlPaint.DrawFocusRectangleHandle 属性。要运行该示例,请将以下代码粘贴到一个窗体中。将两个名为 Button1Button2 的按钮添加到该窗体中,并确保所有事件都与它们的事件处理程序相连接。

' 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), _
    Button2.ClientRectangle)
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)
{
    ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(Button2.Handle), 
        Button2.ClientRectangle);
}
// This method draws a focus rectangle on Button2 using the 
// handle and client rectangle of Button2.
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   ControlPaint::DrawFocusRectangle( Graphics::FromHwnd( Button2->Handle ), Button2->ClientRectangle );
}
// This method draws a focus rectangle on button2 using the 
// handle and client rectangle of button2.
private void button1_Click(Object sender, System.EventArgs e)
{
    ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(button2.get_Handle()), 
        button2.get_ClientRectangle());
} //button1_Click

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
CreateControl
CreateHandle
Control.CreateParams 属性
DestroyHandle
IsHandleCreated
OnHandleCreated
RecreateHandle
RecreatingHandle
UpdateStyles