Inherited handler problem.

K

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.
 
A

aaron.kempf

personalyl I dont know who the hell came up with this syntax

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


that is TOO VERBOSE

move back to VB6
or change to PHP

-Aaron
 
R

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.
 
M

Master Programmer

personalyl I dont know who the hell came up with this syntax

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


that is TOO VERBOSE

move back to VB6
or change to PHP

-Aaron
 
P

Phill W.

kosecki said:
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.
 
P

Phill W.

kosecki said:
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.
 

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