Checking if form is modal

  • Thread starter Thread starter MuZZy
  • Start date Start date
M

MuZZy

Hi,

How do i check if form was called as a dialog vs. non-modal?
In .NET WinForms there is a Modal property, but it doesn't exist in .NETCF

Any ideas would be highly appreciated!

Thank you,
Andrey
 
Since you're the one calling it, set a property if you need it.

-Chris


The problem is that I can call the form both ways, but the form itself has to act differently
depending on call type, so it has to know hwo it was called
 
Add a public property to the form e.g. IsModal then when you call the form:-

Dim mycustomform As New CustomForm
mycustomform.IsModal = True
mycustomform.ShowDialog()

or

Dim mycustomform As New CustomForm
mycustomform.IsModal = False
mycustomform.Show()

Peter
 
I suppose the best way could be to declare interface IModalDialog with
declared property Modal and use this interface for all your forms:

public interface IModalDialog
{
public bool Modal {get; set;}
}

public class Form1 : Form, IModalDialog
{
bool _modal;
public bool Modal
{
set
{
_modal = value;
}
}

...
}

Then to set that you are calling form as Modal use this code:

Form1 f = new Form1();
((IModalDialog)f).Modal = true;
f.ShowDialog();

Though if loosing of form designer is not an issue in your case it will
be better to follow Peter's suggestion.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top