468,741 Members | 1,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,741 developers. It's quick & easy.

Problem with the event in inherited form

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
4 2419
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
"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
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
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.

Similar topics

reply views Thread by 42 | last post: by
6 posts views Thread by crk2 | last post: by
7 posts views Thread by Sergey Poberezovskiy | last post: by
14 posts views Thread by Altman | last post: by
4 posts views Thread by Rod Gill | last post: by
4 posts views Thread by asad.naeem | last post: by
6 posts views Thread by Joel | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.