共用方式為


Control.Handle 屬性

定義

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

public:
 property IntPtr Handle { IntPtr get(); };
[System.ComponentModel.Browsable(false)]
public IntPtr Handle { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Handle : nativeint
Public ReadOnly Property Handle As IntPtr

屬性值

IntPtr

nativeint

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

實作

屬性

範例

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

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

備註

屬性的值 Handle 是 Windows HWND 。 如果尚未建立控制碼,則參考此屬性將會強制建立控制碼。

適用於

另請參閱