Burak Avcı
Burak Avcı

Reputation: 67

Blocking Show Event Of A Form;

I'm trying to write a custom dialog.Everything is good but I don't want my Dialog be callable with Show() event.Anyway to block this ?

Upvotes: 1

Views: 46

Answers (1)

Servy
Servy

Reputation: 203812

If your class inherits from Form it's not possible. Show is not virtual, so you can't override it. You should shadow it, and have it throw an exception or call ShowDialog internally (there is no way to remove it as an option entirely), but then any caller that just types the variable as a Form can still call Show, bypassing your implementation.

The only option available to you would be for your class to not inherit from Form. You'd need to design your type to use composition rather than inheritance. Have a Form property within your type's definition, and manipulate it, add controls to it, etc. as you might normally manipulate the type itself.

You would need to explicitly create members for whatever functionality that you want to expose externally, redirecting the appropriate calls to the encapsulated form (for methods such as ShowDialog).

Upvotes: 3

Related Questions