472,782 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

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 1946
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
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
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
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
11
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
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
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
by: AMP | last post by:
Hello, I have this in form1: namespace Pass { public partial class Form1 : Form { public Form2 form2; public Form1() {
3
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
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...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.