473,854 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events

Can events be used to notify an object that something has happened and it
needs to take some action?

Most of the documentation on events makes them sound like they work the
other way around, that is, an object raises an event to inform other objects
that something happened. I need the ability for many objects to notify a
single object that some event has occurred. e.g. similar to LostFocus.

In C++, I would have used SendMessage() to inform the object that it needs
to take some action but I can't find anything in C# to accomplish the same
thing.

Thanks,
Tom
Nov 15 '05 #1
3 4212
Well, the object you want notified by the other objects could have a public
Notify() method. You could implement it asynchronously, if you need it to
return immediately. Notify() could also take a parameter of this, indicating
which caller called it...
"Tom Bean" <tb***@t-a-c.com> wrote in message
news:#v******** ******@TK2MSFTN GP12.phx.gbl...
Can events be used to notify an object that something has happened and it
needs to take some action?

Most of the documentation on events makes them sound like they work the
other way around, that is, an object raises an event to inform other objects that something happened. I need the ability for many objects to notify a
single object that some event has occurred. e.g. similar to LostFocus.

In C++, I would have used SendMessage() to inform the object that it needs
to take some action but I can't find anything in C# to accomplish the same
thing.

Thanks,
Tom

Nov 15 '05 #2
If the event you need isn't already provided by the control (something like
Leave) I don't see how you could avoid writing code in each of these other
controls to call the notify event, or function, or whatever you use to
implement it. So you're saying that you have to subclass all these controls
because the events already given don't do what you need? I would agree with
the last two posters. Either make each of your controls call a public method
on the notifying control, with some sort of identification of the sender, or
make a new event delegate and add that event to each of the notifying
controls, let the class receiving the notification subscribe to each of
those events, and then add logic in each of the controls with the events to
fire the event when appropriate.

Chris

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:#1******** ******@TK2MSFTN GP10.phx.gbl...
Andrew,

That would mean that all kinds of objects, like textboxes, comboboxes,
listboxes...wou ld have to have the same notify event. That's a lot of
duplicate code in the other objects to just be able to notify a single
object that something has happened,

Tom

"andrew lowe" <andrew [dot] lowe [at] geac [.] com> wrote in message
news:er******** ********@tk2msf tngp13.phx.gbl. ..

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Can events be used to notify an object that something has happened and it needs to take some action?

Most of the documentation on events makes them sound like they work the other way around, that is, an object raises an event to inform other objects
that something happened. I need the ability for many objects to
notify a single object that some event has occurred. e.g. similar to LostFocus.


Tom,

Whats wrong with having the single object subscribe to the each of the

other
objects "notify" event(s) ?

andrew


Nov 15 '05 #3
Chris,

I did as you and the others recommended and implemented a public method that
the other controls can call to notify the control about the event. After
thinking about it, I suppose that's not any different than using
SendMessage() in C++ which in the final analysis is just a call to a public
method.

Thanks,
Tom

"Chris Capel" <ch***@ibanktec h.net.zerospam> wrote in message
news:O3******** ********@TK2MSF TNGP10.phx.gbl. ..
If the event you need isn't already provided by the control (something like Leave) I don't see how you could avoid writing code in each of these other
controls to call the notify event, or function, or whatever you use to
implement it. So you're saying that you have to subclass all these controls because the events already given don't do what you need? I would agree with the last two posters. Either make each of your controls call a public method on the notifying control, with some sort of identification of the sender, or make a new event delegate and add that event to each of the notifying
controls, let the class receiving the notification subscribe to each of
those events, and then add logic in each of the controls with the events to fire the event when appropriate.

Chris

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:#1******** ******@TK2MSFTN GP10.phx.gbl...
Andrew,

That would mean that all kinds of objects, like textboxes, comboboxes,
listboxes...wou ld have to have the same notify event. That's a lot of
duplicate code in the other objects to just be able to notify a single
object that something has happened,

Tom

"andrew lowe" <andrew [dot] lowe [at] geac [.] com> wrote in message
news:er******** ********@tk2msf tngp13.phx.gbl. ..

"Tom Bean" <tb***@t-a-c.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> Can events be used to notify an object that something has happened and
it
> needs to take some action?
>
> Most of the documentation on events makes them sound like they work the > other way around, that is, an object raises an event to inform other
objects
> that something happened. I need the ability for many objects to

notify
a
> single object that some event has occurred. e.g. similar to

LostFocus.
Tom,

Whats wrong with having the single object subscribe to the each of the

other
objects "notify" event(s) ?

andrew



Nov 15 '05 #4

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

Similar topics

3
2040
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When DataNode is changed, it raises "Changed" event. The class has a reference to the DataNode it is being contained in: - DataTree - tree like data structure that contains DataNodes; When
6
13251
by: Saso Zagoranski | last post by:
Hi! How can I unregister all the events registered to a control? I have seen a piece of code in another thread, which gets all the registered handlers for a specific event. Let's say I have a CustomTextBox : TextBox, which has quite a lot of events... Do I put unregistering code for all the possible events in the Dispose method? Or is there another way?
14
12169
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
2
1854
by: Bob Rundle | last post by:
I have the following code, which appears to be working. However it doesn't look right. The part I am wondering about is the logic in DisconnectEvents(). This logic creates a new delegate and then expects to find that delegate in the list of event handlers. What is the proper way of writing this? Regards, Bob Rundle
4
22895
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on when to use one over another? If anyone could provide any additional info, your comments, best practices, any good articles, specific examples, etc. Thank you
11
1896
by: Nicky Smith | last post by:
Hello, I'm studying a book on VB.net Win apps, and I'm reading a section on events and delegates and raising events. Is it just me, or is this not just subs dressed up as something else? I mean, for one, delegates point to subs, so when you call a delegate, why not just call the sub dierectly and not bother adding the extra code involved adding the delegate?
30
3667
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment it seems to me that Microsoft has developed similar functionality via two keywords. I do understand that an event offers better encapsulation as the underlying delegate is private, but is that all ? -- Regards
5
4387
by: Richard Maher | last post by:
Hi, Here I mean "User" in the Programmer or Javascript sense. I merely wish to programmatically trigger an Event. It would be absolutely fantastic if there was a (Form level?) ONUSEREVENT() and a setEvent() function but, in the absence of this, is it not possible to use DOM to change an object's properties resulting in a state-change event? I have tried with ONCHANGE() and that only seems to work if the "interactive" user changes the...
14
2228
by: xoozlez | last post by:
Hi there, I have a registration form where I like to filter out the past events of 2007. This is the code I am using : strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd, EventTimeBegin, Category FROM Events WHERE EventDateBegin >'01/01/2008' AND Events.Category LIKE '3' OR Events.Category LIKE '4' OR Events.Category LIKE '5' OR Events.Category LIKE '6' OR Events.Category LIKE '7' OR Events.Category LIKE '8' OR...
1
4912
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
0
9901
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
9751
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11025
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
10682
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
10371
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
7915
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
7082
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
5942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4562
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

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.