Reparent non-modal form to existing application
-
22-07-2019 - |
Question
I would like to be able to show a non-modal form in an already existing application. At the moment I can do something like:
myform.ShowDialog(handleToApp);
but that will create a modal form parented to the application and what I'm really looking for something that isn't modal so when the form loses focus it won't break the flow of control and pester the user about not being closed.
Does anyone know how or if I can do what I'm looking for?
Solution
I found what I was looking for, you have to make a class which looks like this:
public class MapinfoWindowHandle : System.Windows.Forms.IWin32Window
{
private IntPtr handle;
public MapinfoWindowHandle(IntPtr hWnd)
{
handle = hWnd;
}
#region IWin32Window Members
IntPtr System.Windows.Forms.IWin32Window.Handle
{
get { return handle; }
}
#endregion
}
and then you can do this:
IntPtr windowhandle = new IntPtr(hWnd);
MyForm.Show(new MapinfoWindowHandle(windowhandle));
OTHER TIPS
How about a simple myForm.Show()
?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow