views:

180

answers:

2

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 over 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!

A: 
  Dim frmOptions As New YourFormClass()
  Dim res As DialogResult = frmOptions.ShowDialog(me)
Glennular
+2  A: 

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.

clawson
edit this answer so that it presents a clear and obvious solution to the problem posed in the question, then accept it. You will likely get some upvotes.
Sky Sanders