Firing events in vc#

  • Thread starter Thread starter george antony
  • Start date Start date
G

george antony

Can you suggest any most simplest way to fire events
in vC# from any events.
like:

public event loadrecord()

Private sub frmmaster_load(sender,e as eventargs)handles_
frmmaster.load
raiseevent loadrecord()
End Sub
 
Hello Georg

Here is a simple example how to fire event in C#

At firts you should to declare an delegate. It must not be declared inside
of the class, but inside of the namespace you will use it.

public delegate void LoadRecordEventHandler();

Then you should to declare an event based on the delegate. This should be
inside the class.

public event LoadRecordEventHandler LoadRecord

Finally you can fire event just like some other function, but you should
check at firts if there is an event handler, so something like this:

private void frmmaster_load(sender,e as eventargs)
{
if(LoadRecord !=null)
{
/*this line will fire the event*/
LoadRecord();
}
}

I hope this can help you.

Best regards

Damir
 
Back
Top