473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 2636
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
6
by: crk2 | last post by:
Here a simple one. (At least I think it is?) and any help would be truly appreciated. I have an inherited textbox on my form based on a custom texbox control. It looks something like this ...
7
by: Sergey Poberezovskiy | last post by:
Hi, I created two base forms: frmList and frmDetail, compiled them into a dll, and then want to use in my new project. The problem: When I created new inherited form, say frmClients, I cannot...
14
by: Altman | last post by:
Ok I have a control that is inherited from another class. In the child I put msgbox(me.name) in the load event. What always pops up is the name of the parent class and not the name of the...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
4
by: asad.naeem | last post by:
hi to all this is the problem about inheritence. I have designed a form with some essential controls which are required for every form which will inherited from it. for example i have Button1 on...
6
by: Joel | last post by:
2 Questions: (1) The documentation says application.run() creates a standard message loop on the current thread and "optionally" shows a form. This is really confusing because I was of the...
4
by: fahimrauf | last post by:
Hy Friends, Using visual inheritance feature of .net, I've inherited a Form (Form2) from an existing form (Form1) of the same assembly or project. It's perfectly inherited and when I run the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.