简体   繁体   中英

ShowDialog(owner) is hiding behind/not showing even though I am supplying owner IWin32Window

Please do not close the question straight away. The almost similar problem is also discussed in the following threads.

  1. Windows Forms and ShowDialog problem
  2. Form.ShowDialog() or Form.ShowDialog(this)?

But, these do not solve my problem. The problem never occurred in my development machine. It occurred in the user machine but not always. In fact it occurred only 3 or 4 times.

When it happens it seems the application/calling form is frozen. If I can guess (as I am not seeing it on the screen) where the close button is and click on it on the called form, it closes and application goes back to usable state until it occurs again.

My views are encapsulated within the presenter, so I am not calling ShowDialog() from within the view but through the presenter.

MainPresenter
{
    MainPresenter(IMainView view)
    {
        _view = view;
    }
    …
    …
    OpenSecondView()
    {
        var secondPresenter =_presenterFactory.Create<SecondPresenter>();
        secondPresenter.Ininialize(_view);
    }
}

// Initialize method in the SecondPresenter
Initialize(owner)
{
    _secondView.ShowDialog(owner); 
}

I am using observing presenter style of MVP explained here http://www.aspiringcraftsman.com/2008/11/23/model-view-presenter-styles/

Questions:

  1. How can I reproduce the problem in my development machine and fix it?
  2. If I use Show() and set TopMost = true , is it possible this problem to occur?
  3. What are the things I should consider that may cause this problem?

If Show() absolutely guarantees that the problem will not occur, I will go with Show() . I kind of lost faith in ShowDialog() on this.

Any help will be greatly appreciated.


** The problem does not occur for a specific screen/view. It occurs randomly.

** For all the forms except main form, ShowInTaskBar is set to false.

您是否尝试在表单的load事件中添加this.Activate() ,因为我遇到了类似的问题。

您可以尝试使用TopMost = true作为表单

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM