My application is a vb6 executable, but some newer forms in the system are written in C#. I would like to be able to set the C# form\'s Owner property using a handle to the
So you are calling a C# Windows Form class from VB6, which means you are probably using either Show() or ShowDialog(), correct? Both of those methods also take an IWin32Window parameter, which simply defines an object that returns an IntPtr property named Handle.
So...you need to add an overloaded constructor (or ShowDialog method) for your Windows Forms classes which take a long as a parameter so you can pass the VB6 hwnd to the form. Once inside the C# code, you need to create an IntPtr from the hwnd and assign it to a NativeWindow object and then pass that as the owner.
Something like this should work, although it's untested:
public DialogResult ShowDialog(long hwnd)
{
IntPtr handle = new IntPtr(hwnd);
try
{
NativeWindow nativeWindow = new NativeWindow();
nativeWindow.AssignHandle(handle);
return this.ShowDialog(nativeWindow);
}
finally
{
handle = IntPtr.Zero;
}
}