about event handlers

T

Tony

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 the base class which is EventArgs so because of
this the second parameters could in all cases be EventArgs which had be be
cased
in the most cases to the the actual referenced event argument object before
accessing the referenced object.

Here I have some examples
private void textBoxAge_KeyPress(object sender, KeyPressEventArgs e)
private void textBoxAge_Validating(object sender, CancelEventArgs e)
private void textBox_TextChanged(object sender, EventArgs e)

//Tony
 
T

Tony

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.

Give me some comment about which one to use according to OOP.

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top