add code to buttons of an inherited form

  • Thread starter Thread starter Cheung
  • Start date Start date
C

Cheung

Guest
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 cant edit/add code on buttons inherited. Why? What can I do if I want to add code to it??
Thanks
 
You can either override the Sub in the base form which handles the event:

Code:
Public Overrides Sub mySub(blah)
End Sub

or add another event handler to the control:

Code:
AddHandler cmdMyButton.Click, AddressOf myNewFunction(sig)
 
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?
 
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.
 
Thank a lot for your advice. I now know how to do it.
Actually, my problem was I didnt 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!!
 
Back
Top