473,769 Members | 7,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherited event handlers

joe
Happy New Year to you all and may the source be with you!

I have a class, which handles an event and I derive from
this class. I dont want the event handler in the base
class to be called anymore as it does things I dont want
it to do. I want to handle the event in the derived class.
How do I do it?
One way is to declare the event handler in the base class
as protected virtual.
Is there another way?

class A
{
public ClassWithEventC alledMyEvent c;
this.c.MyEvent+ =new EventHandler(My EventHandler);
private void MyEventHandler( ...)
{
// I DONT WANT THIS CALLED IN THE DERIVED CLASS
}
}

class B:A
{
this.MyEvent+=n ew EventHandler(My DerivedEventHan dler);
private void MyDerivedEventH andler(...)
{
// I WANT THIS CALLED ONLY
}
}

Thanks,
Nov 15 '05 #1
1 3355
the issue is how you register the event handler.. whereever your event +=
handler statement is, that's where the inheritance will or won't affect the
derived class.

HTH.
"joe" <an*******@disc ussions.microso ft.com> wrote in message
news:05******** *************** *****@phx.gbl.. .
Happy New Year to you all and may the source be with you!

I have a class, which handles an event and I derive from
this class. I dont want the event handler in the base
class to be called anymore as it does things I dont want
it to do. I want to handle the event in the derived class.
How do I do it?
One way is to declare the event handler in the base class
as protected virtual.
Is there another way?

class A
{
public ClassWithEventC alledMyEvent c;
this.c.MyEvent+ =new EventHandler(My EventHandler);
private void MyEventHandler( ...)
{
// I DONT WANT THIS CALLED IN THE DERIVED CLASS
}
}

class B:A
{
this.MyEvent+=n ew EventHandler(My DerivedEventHan dler);
private void MyDerivedEventH andler(...)
{
// I WANT THIS CALLED ONLY
}
}

Thanks,

Nov 15 '05 #2

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

Similar topics

10
3604
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script language="JavaScript" type="text/javascript"> function show(that) { if (box.style.visibility=='hidden') { that.style.visibility = 'visible'}; }
4
2387
by: Krzysztof | last post by:
Hi all I got 2 UserControl. First with layout (grid + two buttons) Secon is inerited control from this with layout, and I want to add to all butons some functionality... but I dont see this buttons in design mode. Why? What I do wrong? Regards Krzysztof
0
1299
by: seven | last post by:
I have a base page with an HTMLForm object (added to the base page control heiarchy during Init). In the design of pages derived from this base page, I can choose to create controls and add them to the HTMLForm object I'm inheriting, to create a postback form. And on one particular page I'm doing just that; defining controls on the derived page (during Init) and adding these controls to the inherited HTMLForm object's control...
2
5312
by: Giovanni Bassi | last post by:
Hello All, I have encountered a problem. I am using visual inheritance and my base form adds an event handler on Form Load using the AddHandler Keyword. The problem is that if the Event Handler code is there, when I create the inherited form I get the error "Object Reference not set to an instance of an object". If it is not I get no error. I have tried leaving this code in the forms Sub New, but it produces the
13
2242
by: Lorne Smith | last post by:
Hi, First, sorry for the crosspost, but it seemed appropriate... :) I've come accross what I consider to be a bug, but I don't know if it's already known or not. (VS .Net 2003 Pro - VB.Net) Whilst playing with inherited forms, I created a simple base form containing a single button. I set this buttons' Click event to be public overridable and put "me.Close" in the code.
16
2516
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some of properties or assign event handlers. I need to be able to clone the manipulated control at runtime. I could use the Clone method of some objects (like Font, Style, String,
14
8639
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event handlers are set like the old one. Is there a way to do this job? For example, is there a way to use EventInfo object to get all event handlers of the old control in runtime and set my new cloned control events to the event handlers of the old...
6
931
by: kosecki | last post by:
Hi, I've problem with button click handler. In a short brief my program looks like this: there is form invoice with is base class for invoice_edit form. invoice form has public button "save" with modifers option set to public
4
2001
by: Mihai | last post by:
Hi ! I use VB.Net 2005. I created an inherited user control based on a previosly created user control.Everything is Ok . I can run this control with f5, everything is fine. When I close Visual Studio and a open it again and load my project I have the error: One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while
2
1463
by: alexia.bee | last post by:
Hi All, I have window based app which has two classes. Class A and Clas B Call B Inherits from Class A. Class A has events. How do I cause Class B not to use Class A events. For example: Class A Form_load is being fired even when Class B form is being loaded. There are other events in Class A( Datagridview events) are
0
9589
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
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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
7413
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
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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.