Control.Handle 属性

定义

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

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

属性值

IntPtr

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

实现

属性

示例

下面的代码示例演示了如何使用 ControlPaint.DrawFocusRectangleHandle 属性。 若要运行示例,请将以下代码粘贴到窗体中。 添加两个命名Button1``Button2按钮和窗体,并确保所有事件都连接到其事件处理程序。

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);
}

注解

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

适用于

产品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅