raven
raven

Reputation: 2564

How can I tell if a form was displayed with ShowDialog?

I'm developing a custom control that doesn't inherit from Button. I want to implement a functionality similar to the DialogResult from the standard button, setting the FormParent.DialogResult to the specified value on PerformClick and then closing it.

However, I need to know if the form has been shown with ShowDialog instead of Show (i.e., if it's a modal window).

Is there an easy way to achieve this?

Upvotes: 2

Views: 499

Answers (1)

driis
driis

Reputation: 164291

Use the Form.Modal property, eg:

if(this.Modal)
    Debug.WriteLine("Hooray, I am a modal form");

Upvotes: 6

Related Questions