ShowDialog and this.Modal

  • Thread starter Thread starter Magnus Lindberg
  • Start date 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,
 
* "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.
 
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.
 
Hi Magnus,

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

Cheers

Doug Forster
 
Back
Top