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 . Чтобы запустить пример, вставьте следующий код в форму. Добавьте в форму две кнопки с именами Button1 и Button2 и убедитесь, что все события подключены к их обработчикам событий.

// 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. Если дескриптор еще не создан, ссылка на это свойство приведет к принудительному созданию дескриптора.

Применяется к

См. также раздел