Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to override a click method in a button on a form?
Message
De
18/06/2004 20:40:33
 
 
À
18/06/2004 20:16:49
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00913730
Message ID:
00915282
Vues:
14
Mark,

>That in .Net, in order to step into base class methods of controls on a form, I have to find the source for that code and put my breakpoint there in the base class.

OK, maybe I wasn't being precise enough ... this is only a problem with eventhandlers, not other methods. So if you have a method, MyMethod, in a base class, MyControl, and you've dropped that control on your form and called it oControl, and you need to call that method in your form code, you'd have:
oControl.MyMethod()
and you can set a breakpoint there and you'll be able to step into the base class method at that point. The reason this doesn't work for eventhandlers is because you aren't specifically calling the base class's eventhandler from your form. That's not how eventhandlers work. If a control that's dropped on your form has an eventhandler in it's code, then that eventhandler will always execute regardless of whether you have an eventhandler for that control on your form or not.

>And if I have a control that I want to drop on a form in 5 different places, and I need to override a method in each of these controls, I have to first sub-class that control into 5 different classes, override my method there, and then drop these different classes on the form.

Yep. Or another option to further confuse you <g>, as Kevin briefly touched on, are Interfaces. If you put methods in your form instead of in the controls, and have that form Implement a particular interface, then the controls can check to see if their parent form has implemented that interface and if so, then those particular methods are guaranteed to exist (that's what implementing an interface means) and the controls can call this.parentform.MyMethod(). Chew on that for awhile and see if you get it. =)

>Is this something that you and other VFPers miss badly too?

Nah, you get used to doing things the .NET way pretty fast. I did at least, can't speak for others.

~~Bonnie


>Thanks for your reply again, Bonnie. Am I the only one who thinks, Hey, this seems like a "pain" compared to how easy it was in VFP? That in .Net, in order to step into base class methods of controls on a form, I have to find the source for that code and put my breakpoint there in the base class. And if I have a control that I want to drop on a form in 5 different places, and I need to override a method in each of these controls, I have to first sub-class that control into 5 different classes, override my method there, and then drop these different classes on the form. Whereas, in VFP, I could drop that same control on the form 5 times and override that method in each instance on the form. Is this something that you and other VFPers miss badly too? I'd like to know if I'm not alone, or is this not a problem for people. Thanks again!
>
>>Mark,
>>
>>>>So, I can't do this in .Net? And therefore, would I have to go into the base class and put a breakpoint there?
>>
>>Right. The reason that you have to put the breakpoint in the base class in the case of eventhandlers is because the eventhandler in the base class executes before the eventhandler you've created on your form. And you can't do a base.ClickHandler() because you can't override a button's Click eventhandler in the form, you can only override it in the sub-class of the button.
>>
>>>>A more practical question/example would maybe be this... If I create a button class that does some special stuff, and I create a "Hook" method in the class for the developer to put some custom code when he uses my button on his form. Is it true then that in order for the developer to be able to enter his hook method code, he would have to first, sub-class the button (saving it in a .cs file), enter his hook code there, and then drag his sub-classed button on the form? Gee, if that's true, then I'm really starting to miss VFP already! :)
>>
>>Yes, the developer would only be able to write his own "Hook" code in a sub-class of your button. But, there's no reason to have one .cs file for every sub-classed control!!! That would be crazy. You can easily put all your sub-classed controls into one .cs file and they can be easily dragged to the form from the ToolBox.
>>
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform