Joel Barsotti
Joel Barsotti

Reputation: 3089

Getting the handle of window in C#

I'm trying to do some P/Invoke stuff and need the handle of the current window.

I found Getting the handle of window in C#

But it appears that only works in WPF. Is there a winForms equivalent?

Upvotes: 12

Views: 41352

Answers (2)

ZokiManas
ZokiManas

Reputation: 722

Try this in your form:

IntPtr myHandle = this.Handle;

It will return the handle of the form.

Upvotes: 6

dtb
dtb

Reputation: 217391

Control.Handle

An IntPtr that contains the window handle (HWND) of the control.

Upvotes: 27

Related Questions