共用方式為


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.DrawFocusRectangle 和 屬性 Handle 。 要執行範例,請將以下程式碼貼上表單。 在表單中新增兩個名為 Button1Button2 的按鈕,並確保所有事件都與其事件處理程序連結。

// 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。 如果帳柄尚未建立,引用此屬性會強制建立該手把。

適用於

另請參閱