Export (0) Print
Expand All

NativeWindow.Handle Property

Gets the handle for this window.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

abstract Handle : IntPtr with get 
override Handle : IntPtr with get

Property Value

Type: System.IntPtr
If successful, an IntPtr representing the handle to the associated native Win32 window; otherwise, 0 if no handle is associated with the window.

Implements

IWin32Window.Handle

Use this method when calling Windows API methods that require a handle for a window or control.

The following code example demonstrates creating a window with a specific operating system window class name. The example creates a class that inherits from NativeWindow to accomplish this. The example also demonstrates overriding the OnHandleChange method to be notified when the Handle changes.

The MyNativeWindow class creates a new window with the ClassName set to BUTTON. This creates a Win32 button window. The location and size of the button is set, along with specifying additional window styles. The class demonstrates how to use the CreateHandle method and override the WndProc method to intercept window messages that are received. Although the example looks for the WM_ACTIVATEAPP message, this could be replaced in a real program with window messages specific to the type created.

NoteNote

Some control types send their window messages to the window parent instead of the window. See the Windows Platform SDK for more information.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft