By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

Problem with the event in inherited form

P: n/a
Hi:

My base form has a button, when click it will call MessageBox.Show(
"Base form" ). I inherite a child form from the base and assign a
button click event to the same button which will call MessageBox.Show(
"Inherited form" ). I run my application, and load the clild form,
click the button it show both message !!!
Is there any way to control the event sequence so that it only show
the child form event, or i can control whether to trigger the base
form event or not.

Thanks
JCVoon


Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In the base form class, mark the routine as Overridable:

Public Overridable Sub Button1_Click(...) Handles ...

In the inherited class

Public Overrides Sub Button1_Click(...)

Do not use the Handles statement in the inherited form.

To get the base form code to process, add this code to the event handler in
the inherited form:

MyBase.Button1_Click(Nothing, Nothing)

www.charlesfarriersoftware.com

"JC Voon" wrote:
Hi:

My base form has a button, when click it will call MessageBox.Show(
"Base form" ). I inherite a child form from the base and assign a
button click event to the same button which will call MessageBox.Show(
"Inherited form" ). I run my application, and load the clild form,
click the button it show both message !!!
Is there any way to control the event sequence so that it only show
the child form event, or i can control whether to trigger the base
form event or not.

Thanks
JCVoon


Nov 21 '05 #2

P: n/a
"JC Voon" <jc*******@yahoo.com> schrieb:
My base form has a button, when click it will call MessageBox.Show(
"Base form" ). I inherite a child form from the base and assign a
button click event to the same button which will call MessageBox.Show(
"Inherited form" ). I run my application, and load the clild form,
click the button it show both message !!!


You may want to remove the handler added in the base class in the derived
class:

\\\
RemoveHandler Me.Button1.Click, AddressOf MyBase.Button1_Click
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

P: n/a
Hi JC

I would deal with this by having a Protected Overridable method in your base
class, and in your event handler, call this method. Then in the derived
class, override the method.

Base Form:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
ClickThing()
End Sub

Protected Overridable Sub ClickThing()
MessageBox.Show("base")
End Sub

Derived Form:
Protected Overrides Sub ClickThing()
MessageBox.Show("derived")
End Sub

HTH

Nigel Armstrong

"JC Voon" wrote:
Hi:

My base form has a button, when click it will call MessageBox.Show(
"Base form" ). I inherite a child form from the base and assign a
button click event to the same button which will call MessageBox.Show(
"Inherited form" ). I run my application, and load the clild form,
click the button it show both message !!!
Is there any way to control the event sequence so that it only show
the child form event, or i can control whether to trigger the base
form event or not.

Thanks
JCVoon


Nov 21 '05 #4

P: n/a
Charlie, Herfried K. Wagner, Nigle Armstrong:

Thank for the reply. I've choose Charlie approch.
Is there any way to change the way IDE generate event ? If every event
is generate using public instead of private, it will save a lot of
work.

Cheers
JCVoon

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.