Home All Groups Group Topic Archive Search About

Inherited form problem

Author
13 Jul 2006 10:26 AM
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

Author
13 Jul 2006 12:27 PM
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

asad.na***@gmail.com wrote:

Show quoteHide quote
>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
>

>
Author
13 Jul 2006 12:57 PM
asad.naeem
but i have some code related to inherited form but in some cases i
want to stop that code to execute.
tomb wrote:
Show quoteHide quote
> 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
>
> asad.na***@gmail.com wrote:
>
> >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
> >
> > 
> >
Author
13 Jul 2006 2:17 PM
Terry
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.

--
Terry


Show quoteHide quote
"asad.na***@gmail.com" wrote:

>  but i have some code related to inherited form but in some cases i
> want to stop that code to execute.
> tomb wrote:
> > 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
> >
> > asad.na***@gmail.com wrote:
> >
> > >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
> > >
> > > 
> > >
>
>
Author
14 Jul 2006 9:06 AM
R. MacDonald
Hello, Asad,

I'm not sure that I understand the problem.

Why can't you just put the code of the inherited form's event handler
into a conditional block?  I.e. something like:

     Private Sub Button1_Click(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) _
                    Handles Button1.Click
         If (Appropriate...) Then
        Do actions...
         End If
     End Sub

Is it actually the code of the event handler in the Base form that you
need to inhibit?  In this case, I would either:

a) Define an overridable property to control when the Base form code is
executed.  E.g. something like:

     Protected Overridable ReadOnly _
    Property SkipBaseButtonClick() As Boolean
         Get
             Return False
         End Get
     End Property

Then test this property in the Base form's handler:

     Private Sub Button1_Click(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) _
                    Handles Button1.Click
         If (Not SkipBaseButtonClick) Then
        Do actions...
         End If
     End Sub

Override the property in the inherited form and return either True or
False as appropriate.


or


b) Define a new event in the Base form that includes a "Cancel"
argument.  E.g. something like:

     Public Event BaseButtonClick(_
    ByVal sender As System.Object, _
    ByVal eCancel As System.ComponentModel.CancelEventArgs)

Raise this new event in the Base form handler and only execute the base
form code if the "cancel" property of eCancel is not returned as True.
Then in the inherited form Handle BaseButtonClick instead of Button1.Click.

But let me know if it is something else that you are looking for.

Cheers,
Randy


asad.na***@gmail.com wrote:
Show quoteHide quote
>  but i have some code related to inherited form but in some cases i
> want to stop that code to execute.
> tomb wrote:
>
>>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
>>
>>asad.na***@gmail.com wrote:
>>
>>
>>>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
>>>
>>>
>>>
>
>