Shuhel Ahmed
Shuhel Ahmed

Reputation: 963

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.

Upvotes: 3

Views: 3876

Answers (2)

James
James

Reputation: 2911

Have you tried adding a this.Activate() in the load event for the form, because I have had a similar problem.

Upvotes: 0

aamir
aamir

Reputation: 151

You can try using TopMost = true for the form

Upvotes: 0

Related Questions