ShowDialog and this.Modal

  • Thread starter Magnus Lindberg
  • Start date
M

Magnus Lindberg

Hi,
I'm working on a larger windows application in which I have a form that should
behave as an mdi-child or as a dialog depending on how it is diplayed. I thought
I'd display the form with ShowDialog() to get it modal and then at runtime check
for this.Modal in the form and set some properties.
This however, does not seem to work as this.Modal returns false even though I'm
showing the form using its ShowDialog method.
Here's the conditional mentioned above, just to show the idea.

if (this.Modal)

{

this.ShowInTaskbar = false;

this.MaximizeBox = false;

this.MinimizeBox = false;

this.FormBorderStyle = FormBorderStyle.FixedDialog;

this.SaveButton.Visible = false;

this.ChooseButton.DialogResult = DialogResult.OK;

foreach (Control ctrl in this.Controls)

ctrl.Left -= 72;

}


Thanks,
 
H

Herfried K. Wagner [MVP]

* "Magnus Lindberg said:
I'm working on a larger windows application in which I have a form that should
behave as an mdi-child or as a dialog depending on how it is diplayed. I thought
I'd display the form with ShowDialog() to get it modal and then at runtime check
for this.Modal in the form and set some properties.
This however, does not seem to work as this.Modal returns false even though I'm
showing the form using its ShowDialog method.

You cannot show a MDI child modally.
 
M

Magnus Lindberg

Herfried K. Wagner said:
You cannot show a MDI child modally.

But in the case where the form is shown modally, it is not an MDI child.
The application either sets the MdiParent property of the form and display it
with Show(), or it doesn't bother with MdiParent and just calls ShowDialog().
The form, when displayed with ShowDialog is clearly modal since I can't interact
with any other part of the application, yet this.Modal in the forms constructor
returns false.
I'm beginning to think that I have to check the Modal-property from outside of
the form.
 
E

Eric Newton

Maybe try checking the mdiParent property for the same logic?

Just a thought...


--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]
 
D

Doug Forster

Hi Magnus,

Why don't you just write your own Show method and set a flag before calling
ShowDialog.

Cheers

Doug Forster
 

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