473,513 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about using eventArgs

Hello!

One more thing assume I create an event and an object derived from the
eventArgs containing some info about the event.
Then create another event also with an object derived from the eventArgs
containing some info about the
event.

When creating the event handler I have two choices either use EventArgs as
the second parametr and cast to the actual type
or
use two separate event handler with the actual type as the second paramer.

So does it exist some recommended guidline to which one to use.
I would say use different event handler unles they they are logically
connected in some way.

Is it possible to say anything about which of these two alternatives is the
best choice ?

//Tony
Jun 27 '08 #1
3 1984
On Jun 25, 3:29*pm, "Tony" <johansson.anders...@telia.comwrote:
One more thing assume I create an event and an object derived from the
eventArgs containing some info about the event.
Then create another event also with an object derived from the eventArgs
containing some info about the
event.

When creating the event handler I have two choices either use EventArgs as
the second parametr and cast to the actual type
or
use two separate event handler with the actual type as the second paramer..

So does it exist some recommended guidline to which one to use.
I would say use different event handler unles they they are logically
connected in some way.

Is it possible to say anything about which of these two alternatives is the
best choice ?
I'm afraid it's difficult to know exactly what you mean because you're
using terminology in a pretty loose manner. However, I'd suggest using
EventHandler<TEventArgsrather than creating your own delegate type
for every event. It makes life a lot more consistent in my view.

Jon
Jun 27 '08 #2
On Jun 25, 6:29*pm, "Tony" <johansson.anders...@telia.comwrote:
One more thing assume I create an event and an object derived from the
eventArgs containing some info about the event.
Then create another event also with an object derived from the eventArgs
containing some info about the
event.

When creating the event handler I have two choices either use EventArgs as
the second parametr and cast to the actual type
or
use two separate event handler with the actual type as the second paramer..

So does it exist some recommended guidline to which one to use.
I would say use different event handler unles they they are logically
connected in some way.

Is it possible to say anything about which of these two alternatives is the
best choice ?
If you are subscribing to two events that are so different in nature
that they use two distinct EventArgs-derived classes, then it is
doubtful that you could get away with one event handler for both.
About the only case where this is true is when your event handler does
not use the EventArgs argument at all - in this case, it is probably
better to write a single handler which just takes EventArgs.

If your EventArgs classes have several properties in common (and not
just names, but actual meanings of those properties), then you might
want to introduce an abstract base class in your hierarchy covering
those properties. Then, event handler can be declared with an argument
of that class and reused, while still having access to all those
common properties.
Jun 27 '08 #3
On Jun 25, 10:29*am, "Tony" <johansson.anders...@telia.comwrote:
Hello!

One more thing assume I create an event and an object derived from the
eventArgs containing some info about the event.
Then create another event also with an object derived from the eventArgs
containing some info about the
event.

When creating the event handler I have two choices either use EventArgs as
the second parametr and cast to the actual type
or
use two separate event handler with the actual type as the second paramer..

So does it exist some recommended guidline to which one to use.
I would say use different event handler unles they they are logically
connected in some way.
It's not very clear from your post the details of your situation.
If you have two events that need different set of arguments (even as
few as only one) then create two classes from EventArgs
Jun 27 '08 #4

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

Similar topics

1
1352
by: e-mid | last post by:
i registered two events with a button. when i press it , how can i know which is fired first? or is there a way to make one of them get fired before the other one? in fact i made a experiment...
6
2479
by: wASP | last post by:
Hello everyone, I'm new to C# and ASP.NET, so pardon my stupidity on this one. I'm having a problem with referencing methods/functions external to a class member function. My code is as...
3
2599
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
11
1202
by: Brian | last post by:
Hi! I am new to VB.net but know enough to kind of dive in. I want to make a text adventure but I am having problems in how I want to store the data for inventory items, characters and such....
2
1613
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing...
12
1263
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, I have added few of the events in some control, example code is: btnControl.GotFocus +=new EventHandler(EventHandlingMethod); btnControl.Click +=new EventHandler(EventHandlingMethod);...
7
10380
by: AMP | last post by:
Hello, I have this in form1: namespace Pass { public partial class Form1 : Form { public Form2 form2; public Form1() {
3
1362
by: Tony | last post by:
Hello! Is it the normal procedure in C# and .NET framework to always use the actual event object which is passed as the second parameters to the event handler. All of them are derived from...
0
1153
by: Tony Johansson | last post by:
Hello! I have a simple application from a book where the actual applications permission doesn't match the permission referenced from the book. My question is written further down. The book is...
1
7098
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
5682
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,...
1
5084
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...
0
4745
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.