Control.Handle Właściwość

Definicja

Pobiera uchwyt okna, do którego jest powiązana kontrolka.

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

Wartość właściwości

IntPtr

nativeint

Element IntPtr zawierający uchwyt okna (HWND) kontrolki.

Implementuje

Atrybuty

Przykłady

Poniższy przykład kodu przedstawia użycie ControlPaint.DrawFocusRectangle właściwości i Handle . Aby uruchomić przykład, wklej następujący kod w formularzu. Dodaj dwa przyciski o nazwie Button1 i Button2 do formularza i upewnij się, że wszystkie zdarzenia są połączone z ich procedurami obsługi zdarzeń.

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

Uwagi

Wartość Handle właściwości to Windows HWND. Jeśli uchwyt nie został jeszcze utworzony, odwołanie się do tej właściwości wymusi utworzenie uchwytu.

Dotyczy

Zobacz też