Home All Groups Group Topic Archive Search About

Inherited handler problem.

Author
22 Nov 2006 8:55 PM
kosecki
Hi,

I've problem with button click handler.

In a short brief my program looks like this:

there is form invoice with is base class for invoice_edit form.

invoice form has public button "save" with modifers option set to
public

invoice_edit form has method which handles save.click and do some code

Public Sub save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles save.Click

there is third form invoice_prod which inherits from invoice_edit and
also handles "save" button with this method declaration:

Public Sub save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles save.Click

So, when I launch my invoice_prod:

invoice_prod.ShowDialog() and click on "save" button involved with
public sub save_click from form invoice_edit executing.

Please help, how to execute method from invoice_prod form.

Author
22 Nov 2006 10:05 PM
RobinS
I'm sorry, I'm confused. Is this right:

You have a base class form form called invoice_edit
that has a Save method in it.

You have a form that inherits from invoice_edit that
is called invoice. This has a "save" button on it.

You have a form that inherits from invoice_edit that
is called invoide_prod. This has a "save" button on it.

Is that right? So what's the problem exactly?

Robin S.
------------------------------------

Show quoteHide quote
"kosecki" <piotrkosin***@gmail.com> wrote in message
news:1164228951.634318.300320@m73g2000cwd.googlegroups.com...
> Hi,
>
> I've problem with button click handler.
>
> In a short brief my program looks like this:
>
> there is form invoice with is base class for invoice_edit form.
>
> invoice form has public button "save" with modifers option set to
> public
>
> invoice_edit form has method which handles save.click and do some code
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> there is third form invoice_prod which inherits from invoice_edit and
> also handles "save" button with this method declaration:
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> So, when I launch my invoice_prod:
>
> invoice_prod.ShowDialog() and click on "save" button involved with
> public sub save_click from form invoice_edit executing.
>
> Please help, how to execute method from invoice_prod form.
>
Author
23 Nov 2006 5:57 AM
Cor Ligthert [MVP]
Kosecki,

Do you mean that you want to shadows the method of  your last button?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vakeyShadows.asp

Cor

Show quoteHide quote
"kosecki" <piotrkosin***@gmail.com> schreef in bericht
news:1164228951.634318.300320@m73g2000cwd.googlegroups.com...
> Hi,
>
> I've problem with button click handler.
>
> In a short brief my program looks like this:
>
> there is form invoice with is base class for invoice_edit form.
>
> invoice form has public button "save" with modifers option set to
> public
>
> invoice_edit form has method which handles save.click and do some code
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> there is third form invoice_prod which inherits from invoice_edit and
> also handles "save" button with this method declaration:
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> So, when I launch my invoice_prod:
>
> invoice_prod.ShowDialog() and click on "save" button involved with
> public sub save_click from form invoice_edit executing.
>
> Please help, how to execute method from invoice_prod form.
>
Author
23 Nov 2006 11:25 AM
Phill W.
kosecki wrote:
Show quoteHide quote
> Hi,
>
> I've problem with button click handler.
>
> In a short brief my program looks like this:
>
> there is form invoice with is base class for invoice_edit form.
>
> invoice form has public button "save" with modifers option set to
> public
>
> invoice_edit form has method which handles save.click and do some code
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> there is third form invoice_prod which inherits from invoice_edit and
> also handles "save" button with this method declaration:
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> So, when I launch my invoice_prod:
>
> invoice_prod.ShowDialog() and click on "save" button involved with
> public sub save_click from form invoice_edit executing.
>
> Please help, how to execute method from invoice_prod form.

When inheriting visual classes, it is *far* better to provide an
Overridable method that performs each action, rather than attaching
event handlers.  I haven't found any way of finding out which, if any,
event handlers exist for a given event and, if you can manipulate them
in code, you can't guarantee the order in which the event handlers might
run.

Going down the "overriding" route, you'd have something like this:

Class InvoiceForm
    Protected WithEvents save As Button

    Protected Overridable Sub OnSaveClick()
       ' Basic functionality goes here
    End Sub

    Private Sub save_Click( ... ) Handles save.Click
       Me.OnSaveClick()
    End Sub

End Class

Class Invoice_Edit
    Inherits InvoiceForm

    Protected Overrides Sub OnSaveClick()
       ' *Alternative* functionality goes here

       ' ' To use the code in InvoiceForm.OnSaveClick, use
       ' MyBase.OnSaveClick()

    End Sub

End Class

Class Invoice_Prod
    Inherits Invoice_Edit

    Protected Overrides Sub OnSaveClick()
       ' Alternative functionality goes here

       ' ' To use the code in Invoice_Edit.OnSaveClick, use
       ' MyBase.OnSaveClick()

       ' NB: You cannot access /InvoiceForm/.OnSaveClick directly
    End Sub

End Class

HTH,
    Phill  W.
Author
23 Nov 2006 11:26 AM
Phill W.
kosecki wrote:
Show quoteHide quote
> Hi,
>
> I've problem with button click handler.
>
> In a short brief my program looks like this:
>
> there is form invoice with is base class for invoice_edit form.
>
> invoice form has public button "save" with modifers option set to
> public
>
> invoice_edit form has method which handles save.click and do some code
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> there is third form invoice_prod which inherits from invoice_edit and
> also handles "save" button with this method declaration:
>
> Public Sub save_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles save.Click
>
> So, when I launch my invoice_prod:
>
> invoice_prod.ShowDialog() and click on "save" button involved with
> public sub save_click from form invoice_edit executing.
>
> Please help, how to execute method from invoice_prod form.

When inheriting visual classes, it is *far* better to provide an
Overridable method that performs each action, rather than attaching
event handlers.  I haven't found any way of finding out which, if any,
event handlers exist for a given event and, if you can manipulate them
in code, you can't guarantee the order in which the event handlers might
run.

Going down the "overriding" route, you'd have something like this:

Class InvoiceForm
    Protected WithEvents save As Button

    Protected Overridable Sub OnSaveClick()
       ' Basic functionality goes here
    End Sub

    Private Sub save_Click( ... ) Handles save.Click
       Me.OnSaveClick()
    End Sub

End Class

Class Invoice_Edit
    Inherits InvoiceForm

    Protected Overrides Sub OnSaveClick()
       ' *Alternative* functionality goes here

       ' ' To use the code in InvoiceForm.OnSaveClick, use
       ' MyBase.OnSaveClick()

    End Sub

End Class

Class Invoice_Prod
    Inherits Invoice_Edit

    Protected Overrides Sub OnSaveClick()
       ' Alternative functionality goes here

       ' ' To use the code in Invoice_Edit.OnSaveClick, use
       ' MyBase.OnSaveClick()

       ' NB: You cannot access /InvoiceForm/.OnSaveClick directly
    End Sub

End Class

HTH,
    Phill  W.