Reparent non-modal form to existing application

2020-03-04 07:56发布

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?

2条回答
放荡不羁爱自由
2楼-- · 2020-03-04 08:01

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));
查看更多
我命由我不由天
3楼-- · 2020-03-04 08:01

How about a simple myForm.Show()?

查看更多
登录 后发表回答