c# - Shown handler in Form's base class in the way of designer -
i have base class inherits form, registers event handler on shown:
class baseclass : form { public baseclass() : base() { shown += new eventhandler(baseclass_shown); } void baseclass_shown(object sender, eventargs e) { close(); messagebox.show("this cannot opened."); } }
now, when subclass form , open in designer, messsage , closes form in designer making impossible me visually edit it.
is there perhaps boolean can use prevent close()
, messagebox
happen?
(little background: close
not called, depends on runtime settings , data)
some events fired in designer well, gives winforms designer wysiwyg ability. notably paint, shown fired, etcetera. designmode property provided allow tell whether event handler running @ design-time. fix:
void baseclass_shown(object sender, eventargs e) { if (!this.designmode) { close(); messagebox.show("this cannot opened."); } }
do note flaw in approach, event fires derived form. might helping much.
Comments
Post a Comment