How to use Form.Show(IWin32Window)

*爱你&永不变心* 提交于 2021-02-17 06:21:07

问题


My goal is to use Form as progress bar of the Visio Application during some long actions.
Which means, the Form should be display on top of the Visio Application.
I also need the Form as non modal dialog (means not Form.ShowDialog()) in order to letting the Visio app to continue works while the Form is appeares.

I've already tried the following steps:

  1. Create a wrapper class that implements the IWin32Window.
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
    public WindowWrapper(IntPtr handle)
    {
        _hwnd = handle;
    }

    public WindowWrapper(Window window)
    {
        _hwnd = new WindowInteropHelper(window).Handle;
    }

    public IntPtr Handle
    {
        get { return _hwnd; }
    }

    private IntPtr _hwnd;
}

from here

  1. Passing the Application.WindowHandle as the owner as follows:
myForm = new Form();
myForm .Show(new WindowWrapper(new IntPtr(Application.WindowHandle)));

from here

but unfortunately, the Application.WindowHandle Does not work well for a particular computer and throws some error (If necessary, i believe i can reproduce it and quote the error/exception).
When i tried the Application.WindowHandle32 instead of Application.WindowHandle there is no error, but the Form go behind the Visio Application instead of display on top of the Visio.

Please help, how can i cause the Form to display on top of the Visio for using the Form as progress bar?

Can you please do some order and explain for me the differences between the following properties of the Visio Application?

  1. Application.WindowHandle

  2. Application.WindowHandle32

  3. Application.InstanceHandle

  4. Application.InstanceHandle32

  5. Application.InstanceHandle64

来源:https://stackoverflow.com/questions/61988104/how-to-use-form-showiwin32window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!