开发者

Form.ShowDialog() does not show form

I've come across a situation where I try to run a simple line of code in a method

Dim res As DialogResult = frmOptions.ShowDialog()

but nothing happens. The dialog box will not appear. If I run this method from another location in the code it executes fine (i.e. displays the form in dialog mode and code executes fine thereafter). Hence, it may be the way in which I arrive at this code that is causing my problem, but I cannot see to find what is wrong.

When I pause the debugger the line of code is highlighted in green but I can't see to step ove开发者_运维百科r it or into it.

Any idea what may cause this to happen, or what I should be looking for that might be causing the problem??

Thanks for the help!


The problem was that the active window, which is set as the owner of the dialog box by default, had it's TopMost property set to true. As a result the dialog box was being displayed behind the owner (TopMost) window.

The dialog box is a modal form, as such other windows are unable to be given focus, hence the program appearing as nothing is happening or working, when in fact the dialog box is just hidden behind the top most form.

The reason the code works on other occasions is because the active window, when the dialog box is loaded, does not have it's TopMost property set to true, thus displaying the dialog box as expected.


I had the same issue. The dialog was blinking visible then disappearing. It was already TopMost, and I tried the other trick of setting it to visible then not visible before showdialog was called, but nothing worked.

Then I checked the other dialog that was working fine and it had ControlBox = true. I tried that, and it worked!


  Dim frmOptions As New YourFormClass()
  Dim res As DialogResult = frmOptions.ShowDialog(me)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜