Guest Cheung Posted May 13, 2002 Posted May 13, 2002 I created a Base form which have buttons on it. I then created a form (called form B) inherited from this Base form. Now, I found I can't edit/add code on buttons inherited. Why? What can I do if I want to add code to it?? Thanks Quote
*Gurus* divil Posted May 13, 2002 *Gurus* Posted May 13, 2002 You can either override the Sub in the base form which handles the event: Public Overrides Sub mySub(blah) End Sub or add another event handler to the control: AddHandler cmdMyButton.Click, AddressOf myNewFunction(sig) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Cheung Posted May 13, 2002 Posted May 13, 2002 Thank for your reply! BTW, where can I enter the code to override the sub in the Base Form. Actually, what I want to do is not "override" the parent code. Instead, I want to "extend" it. It means when I click the button, I want to run both the codes in base form and inherited form. Can I do that? Quote
*Gurus* divil Posted May 13, 2002 *Gurus* Posted May 13, 2002 From the dropdown boxes, choose (Overrides) in the left one, then the sub you want to override in the right. Make sure the base sub is marked overridable. Then, in your new sub, you call MyBase.SubName to run that one, then put your new behaviour afterwards. This is how you extend it. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Cheung Posted May 13, 2002 Posted May 13, 2002 Thank a lot for your advice. I now know how to do it. Actually, my problem was I didn't set the property modifier of the button of the base form to "protected". Instead, I set it to friend (default) so that when I double click the button in the child form, there was no reaction. Anyway, Thx!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.