I have been able to successfully wrap my unmanaged Borland C++ dll, and launch it’s forms from a C# .NET 4.0 application. Is it possible to embed a form from the dll directly into a .NET application?
To clarify, the original form is being used as an embedded control in a Borland C++ project already. It essentially looks like a custom control, sitting on a panel within the application.
When I say ’embed’ I mean place INTO a form in the same way you drop buttons, panels, etc on to a form. I’m not looking to just make a child form.
If this is not possible, then perhaps a better question would be how do I embed an unmanged custom control into a .Net application?
Yes, you just need to use some low-level win32 functions from user32.dll : SetParent, GetWindowLog, SetWindowLong , MoveWindow . You can create an empty .NET container control, set the parent of the native window to the .NET control, then (optionally) modify the window style (i.e. to remove borders of native window), and pay attention to resize it together with the .NET control. Note that, at a managed level, the .NET control will be unaware it has any children.
In the .NET control do something like
Then override the WndProc of the .NET control to make it resize the native form appropriately — for example to fill the client area.