473,405 Members | 2,282 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,405 software developers and data experts.

Remove Event Handlers in C#

Hi,

I am currently working on C#.

I need to temporarity add remove event handlers
which i was done in VB.NET using Addhandler and RemoveHandler functions.

How to do it in c#

Thanks in Advance
Prasad Dannani

Nov 17 '05 #1
1 15603
Hi

The += and -= are what you are after.

For example, say I have a combo box and I want to add an event handler
to the index changed event. It is as easy as:

cmbFonts.SelectedIndexChanged += new
EventHandler(cmbFonts_SelectedIndexChanged);

Where my event handling routine matches the signature of the
EventHandler delegate. For example:

private void cmbFonts_SelectedIndexChanged(object sender,
System.EventArgs e)
{
// Do some work here
}

When I want to remove the event handler:
cmbFonts.SelectedIndexChanged -= new
EventHandler(cmbFonts_SelectedIndexChanged);

Cheers
Bill

Nov 17 '05 #2

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

Similar topics

3
by: Peter Oliphant | last post by:
In general, some controls can have events handlers attached to them, typically via the += operator. How does one remove an event handler added this way? Or, just as good for my purposes, how can...
4
by: Matthew Burnside | last post by:
We're creating several different websites all based on a common framework, including a base page from which all pages inherit. This page is responsible for rendering the page layout, etc. I'm...
1
by: Tosch | last post by:
I have an application where I dynamically add controls to a form. Depending on some settings I also add the appropriate handlers using AddHandler. Different handlers are added to say a textbex...
9
by: Charles Law | last post by:
I have a form on which user controls are placed at runtime. When a control is added to the form a handler is added for an event that a high-level object raises, which must be handled by the new...
4
by: Charles Law | last post by:
Is there a way to dynamically remove an event handler from an event without knowing the name of the handler? For example, how can ClassB remove the handler without knowing the name, or how many...
10
by: Franky | last post by:
How Remove All Handler on a event? Like remove all handler on the myButton.Click. Thanks ______________________________ Franky FrankyPDA_NOSPAM_@hotmail.com
2
by: MuZZy | last post by:
Hi, I need to do some custom processing of event handlers assigned to a particular event in my user control, e.g. when you add a handler it should first remove it to make sure any given handler...
2
by: Dinsdale | last post by:
I appreciate anyones help here. I've done a whole ton of cool things in C# and am having difficulty expressing those things in VB. In a program I wrote in C# (which I no longer have source for) I...
4
by: Sergei Shelukhin | last post by:
Hi. I have a <tdelement, with <ain it and <spaninside <a>, all created statically (e.g. poresent in HTML when the page loads). Later I execute the code that adds reference to td in question to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
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...

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.