Jump to content
Xtreme .Net Talk

add code to buttons of an inherited form


Recommended Posts

Guest Cheung
Posted

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

  • *Gurus*
Posted

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)

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

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?

  • *Gurus*
Posted

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.

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

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!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...