Using multiple modal dialogs in a Windows app

M

Mike

Hello,

I have a Windows form that opens a modal dialog window. From there I
can open yet another modal dialog window so I can grab some info to
pass back to the first dialog. Both need to be modal and are launched
like this:
From my main Windows form:
if (formName1.ShowDialog( this ) == DialogResult.OK)
......
From formName1:
if (formName2.ShowDialog( this ) == DialogResult.OK)
......

I have OK buttons on both modal forms that return a DialogResult of OK
and then they do formName.Close(). They both also have a Cancel
button with simply a formName.Close().

My problem is when I close the second dialog window via either a
Cancel or OK, the first one closes with it, and I would like for the
first to stay open :)

Does anyone have any ideas?

Mike
 
K

KWienhold

Hello,

I have a Windows form that opens a modal dialog window. From there I
can open yet another modal dialog window so I can grab some info to
pass back to the first dialog. Both need to be modal and are launched
like this:


if (formName1.ShowDialog( this ) == DialogResult.OK)
......


if (formName2.ShowDialog( this ) == DialogResult.OK)
......

I have OK buttons on both modal forms that return a DialogResult of OK
and then they do formName.Close(). They both also have a Cancel
button with simply a formName.Close().

My problem is when I close the second dialog window via either a
Cancel or OK, the first one closes with it, and I would like for the
first to stay open :)

Does anyone have any ideas?

Mike

I tried reproducing the problem you describe, but it seems to work
fine for me.
Creating 3 windows, each with a button with its DialogResult-Property
set to OK, the first one calling ShowDialog on the second and the
second on the third, behave exactly as expected.
Could you post a short program that still causes the unexpected
behavior?
As a sidenote: You don't actually have to call Close on the form
within a button's click-event if the button has a DialogResult
associated with it, the form will close automatically after the button
is pressed.

Kevin Wienhold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top