Inherited form problem

A

asad.naeem

hi to all
this is the problem about inheritence. I have designed a form with some
essential controls which are required for every form which will
inherited from it. for example i have Button1 on parent form and this
button is visible to me on inherited form.
The problem is:
I have written a click event of the button1 on both of the forms. tell
me the way if i click the button on inherited form only parents' click
event will be called and iherited form's evend wil not be called.

Plz guide me in this regard

Thans in advance
Asad
 
T

tomb

I would suggest not writing a click event in the inherited form. If you
really need that there, then in the logic of that click event, you could
branch to the MyBase.Button1_Click() event instead of processing the
inherited form's code.

T
 
A

asad.naeem

but i have some code related to inherited form but in some cases i
want to stop that code to execute.
 
G

Guest

Hi,
This is from F. Balena's book "Visual Basic 2005: The Language". In the
base form, delegate the base forms btnBotton1.click event to a Protected
Overridabe subroutine with the name OnButton1Click. for example:
Private Sub btnButton1_Click(byval Sender as Object, ....etc
OnButton1Click(e)
end sub

Protected Overridable Sub OnButton1Click(e as EventArgs)
"your code for the base form here"
end sub


then in the derived form:
Protected Overrides Sub OnButton1Click(e as EventArgs)
Then if you want the base form OnButton1Click to run .. call it ...
MyBase.OnButton1Click(e)
and if you dont want it to run ...don't call it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top