473,804 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using events in a inherited form

I currently have a base form that I inherit. The base for has a custom
event. The event will not raise threw the inherited form. I was wondering
if events work threw inheritance or should I use some other method?

--
Chad Miller
President and Director of Software Development
Predictive Concepts, Inc.
www.predictiveconcepts.com
407.327.9910
Nov 20 '05
10 2148
Thanks for the tip!
--
Joe Fallon

"Codemonkey " <hu*********@ho tmail.com> wrote in message
news:uj******** ******@TK2MSFTN GP11.phx.gbl...
Joe,

This isn't the neatest way of doing it (especially with the Form.Load
Event). For example, if you need to catch the Form Load event in both the
base class and the derived class, you are relying on the derived class
calling MyBase.Form_Loa d.

IMHO, a better way of catching the Form.Load event in both the base class
and derived class would be:
--------------------------------
*Base Form*
Private Sub Form_Load(sende r as object, e as EventArgs) handles MyBase.Load
' Do stuff to initialize base form.

End Sub

*Derived Form*
Private Sub Form_Load(sende r as object, e as EventArgs) handles MyBase.Load
' Do stuff to initialize derived form.

End Sub

--------------------------------

Notice that the event handler in both forms is declared with *private*
scope. This will prevent the derived class from overriding the base classes event handler and being called twice.

If you don't need to catch the Form.Load event in the base class, simply
omit the event handler. This way, child classes can catch the event as
normal.
Hope this helps,

Trev.
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I just went through something similar.
In the Base form I double clicked a button control and got the stub with

the
event handler on the end of it.
In the child form I "saved some time" by copying the stub from the Base

form
and accidentally included the event handler. Then I changed it to

Overrides
instead of Overridable.
Anyway the event code ran twice! What a pill finding that one was.

Bottom line - just put the event in the Base form and override it in the
child.

e.g.
Base Form:
Protected Overridable Sub frmSelectBase_L oad(ByVal sender As

System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
'Override this method in child classes. Do NOT include an Event

Handler
in the child class - or it will run twice!
End Sub

Child form:
Protected Overrides Sub frmSelectBase_L oad(ByVal sender As System.Object,
ByVal e As System.EventArg s)
'note the lack of event handler (Handles MyBase.Load)
'do stuff here
End Sub
--
Joe Fallon

"Chad Miller" <ch**@predictiv econcepts.com> wrote in message
news:Gd******** **********@twis ter.tampabay.rr .com...
I currently have a base form that I inherit. The base for has a custom event. The event will not raise threw the inherited form. I was

wondering if events work threw inheritance or should I use some other method?

--
Chad Miller
President and Director of Software Development
Predictive Concepts, Inc.
www.predictiveconcepts.com
407.327.9910



Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2267
by: Edward Diener | last post by:
Is it possible for a derived class to override a property and/or event of its base class ?
2
1918
by: Andrew | last post by:
Hi, friends, I need to raise certain events in my VC# windows control library. Any reference paper or sample source code for help? Thanks a lot...
8
6721
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and contains a few controls anchored to the sides of the form. "frmChild" inherits from "frmBase"... and the controls appear on the inherited form as expected. However things start going wrong when I place addition controls on the "frmChild" form. When I...
2
3972
by: DotNetShadow | last post by:
Hi Guys, I'm trying to work out how events work in VB.NET Basically I want to create a base class that has an Event. I would like all derived classes to inherit this event. I sorta worked out how to do that but the real problem I have is that If I have a base class with an event and derived class 1 and 2 inherit this event. Say derived class 1 creates a new derived class 2 how does this new class 2 get the same event as derived class 1...
2
1096
by: Mark | last post by:
Hi all I just started usuing vb2005 after many years on vb6. I had a go at creating a custom control. I added several events to my control such as 'NewClientAdded' and placed it on a test form. What I'd like to know is how to get the events that I created to appear in the list of events on the host form ( for that control)
2
1393
by: MuZZy | last post by:
Hi, Consider i have this code: // --------------------------------------------------------------------- public delegate void DoSearchEventHandler(Form f, DoSearchEventArgs e); public class DoSearchEventArgs { public String m_sIDColumn; public String m_sQuery; public DoSearchEventArgs(String sQuery, String sIDColumn)
7
2052
by: Jean Paul Mertens | last post by:
Hello, Is there a way to send a string of text to a generic tekst printer under ..NET. Somethings as in the good old days File f = Open("LPT1"); f.Writeline("Blablabla"); The goal is to use an old lineprinter as a log printer printing out each line (incomming allert) at a time without having to build a whole page
53
4763
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code, and .Net2005 code. I'm developing in vb.net 2005. This test sub just reads an input text file, writing out records to another text file, eliminating records that have a '99' in them (it is similar to a CSV file). Some of my concerns are:
0
902
by: DaveL | last post by:
I have a Base Window public class InheritForm:BaseForm when Controls are added i want to add a eventhandler that will fire 1st before the other control events as in the leave and enter events ive tried Control_added event but my events fire after the inherited Controls enter/leave events
0
9707
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.