tags:

views:

65

answers:

2

I need to get the handle of a control as an IntPtr to pass to a screen capture class in vb.Net 3.0. Tried this but get an invalid handle exception.

Dim hwnd As IntPtr = Runtime.InteropServices.GCHandle.Alloc(CanvasMap)

Any help would be greatly appreciated.

Thanks

A: 

There is no 3.0 version of VB.Net. Are you refering instead to the version of VB.Net shipped with VS2008? If so, that's actually VB.Net version 9.0. They didn't reset the version number when switching from VB6, they just kept incrementing.

Is this a WinForms project? If so you can just use CanvasMap.Handle to get access to the control. Note, this property won't be valid until it is actually displayed but this is true for most scenarios.

EDIT OP mentioned this is a WPF application

I'm not sure you can do this for just any control in a WPF application. It's possible to get the handle of a Window instance using the WindowInteropHelper in WPF (link). But this won't work for normal Control instances.

Why do you need the handle? Will it work to have the handle of the containing window?

JaredPar
Get this error when I try CanvasMap.Handle. 'handle' is not a member of 'System.Windows.Controls.Canvas'.
Sorry, this is a WPF app.
I think he meant VB.NET with .NET 3.0.
Matt Olenik
A: 

ctrlSomeControl.Handle?

Daniel A. White