M
Martin Horn
Hi,
I would be grateful if someone can advise me on the following problem I have
encountered.
I have created a test project to demonstrate the problem, it has 2 forms:
Form1, with one button (Button1) on it, as the base class
I have set Button1's modifier to protected
Form 2 inherits Form1
Button1's click event is handled with:
Private Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Base Class action")
End Sub
When form2 is shown and Button1 is clicked I want to replace the base class
action for Button1 with something else specific to the child class, and that
is where I have the problem. I have tried the following without success.
In Form2 Create the following sub
Private Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Child Class Action")
End Sub
Both the Base Class and Child Class routines are called.
So I amended the Form1 Button click routine to
Protected Overridable Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Base Class action")
End Sub
and the Form2 Button Click routine to
Protected Overrides Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Child Class Action")
End Sub
And now the base class routine doesn't get called, but the child class
routine executes twice.
Am I missing something obvious, or am I trying to do something that is
fundamentally wrong.
All advice will be appreciated,
Regards,
Martin Horn
I would be grateful if someone can advise me on the following problem I have
encountered.
I have created a test project to demonstrate the problem, it has 2 forms:
Form1, with one button (Button1) on it, as the base class
I have set Button1's modifier to protected
Form 2 inherits Form1
Button1's click event is handled with:
Private Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Base Class action")
End Sub
When form2 is shown and Button1 is clicked I want to replace the base class
action for Button1 with something else specific to the child class, and that
is where I have the problem. I have tried the following without success.
In Form2 Create the following sub
Private Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Child Class Action")
End Sub
Both the Base Class and Child Class routines are called.
So I amended the Form1 Button click routine to
Protected Overridable Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Base Class action")
End Sub
and the Form2 Button Click routine to
Protected Overrides Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button.Click
Debug.Print("Child Class Action")
End Sub
And now the base class routine doesn't get called, but the child class
routine executes twice.
Am I missing something obvious, or am I trying to do something that is
fundamentally wrong.
All advice will be appreciated,
Regards,
Martin Horn