Creating my events.

  • Thread starter Thread starter Daniel Groh
  • Start date Start date
D

Daniel Groh

How and when should I create my own event ?

When i do this:
public delegate void myEvent(object sender, System.EventArgs e);

What am I doing ?

I tryed to find some sample on net but nothing was enough to understand when
using! =/

Can someone help me ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: (e-mail address removed)
 
Hi,

You are declaring the "template" or the signature of the method that will
handle an event of that kind.

The delegate is the first part you need, the other is the event declaration
itself and then you need a method which must have the same parameters that
the delegated you declared before.

There is a very good explanation of events in the MSDN , just looks for
events in the MSDN index



cheers,
 
Daniel said:
How and when should I create my own event ?

When i do this:
public delegate void myEvent(object sender, System.EventArgs e);

What am I doing ?

[You are creating a new delegate type, so later on, you can do that in
your class. I have to say it's bad naming.

U better delcare
public delegate void MyEventType(object sender, System.EventArg e);

so you can delcare an event using the type you just created.


class MyEventSource
{
.....
public event MyEventType myEvnet;
....

// you can raise the event in any place
void Function RaiseMyEvent()
{
myEvnet( sender, e );
}
}


And then you can register the event in the intersed source in way looks
like:

class MyEventSink
{
MyEventSource myEventSource;

this.myEventSource.myEvent+=new MyEventType(EventHandlerFunction);


public void EventHandlerFunction(object sender, System.EventArg e)
{
// do what ever you like
}
}

I tryed to find some sample on net but nothing was enough to understand when
using! =/

[There are a lot of samples on the Internet, and you need practice the
samples yourself to be able to understand it].
 
Back
Top