Control.Handle 屬性

定義

取得控制項要繫結的目標視窗控制代碼。

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

屬性值

IntPtr

IntPtr,包含控制項的視窗控制代碼 (HWND)。

實作

屬性

範例

下列程式碼範例示範如何使用 ControlPaint.DrawFocusRectangleHandle 屬性。 若要執行範例,請將下列程式碼貼到表單中。 將名為 和 Button2 的兩個 Button1 按鈕新增至表單,並確定所有事件都已連線到其事件處理常式。

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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱