Events
-
Hey, I am creating an alarm clock in c#. I want to create a event that calls a method to , lets say tell the user what time it is. I tried to read all tutorials on events and delegates. Still, I have no idea how to implement things. can anybody show me a very simple example? "To teach is to learn twice"
-
Hey, I am creating an alarm clock in c#. I want to create a event that calls a method to , lets say tell the user what time it is. I tried to read all tutorials on events and delegates. Still, I have no idea how to implement things. can anybody show me a very simple example? "To teach is to learn twice"
public delegate void TimerEventHandler(object sender, TimerEventArgs e);
public class TimerEventArgs : EventArgs
{
//TODO: put in property procedures here for each event argument
}
//---in the class that raises an event---
public event TimerEventHandler TimerRing;
protected OnTimerRing(TimerEventArgs e)
{
if(TimerRing!=null) TimerRing(this,e);
}
//---in the class that consumes the event---
private void TimerRung(object sender, TimerEventArgs e)
{
//handle the event here
}
//---in the method that hooks up the event---
AlarmClock.TimerRing+=new TimerEventHandler(this.TimerRung);"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
Hey, I am creating an alarm clock in c#. I want to create a event that calls a method to , lets say tell the user what time it is. I tried to read all tutorials on events and delegates. Still, I have no idea how to implement things. can anybody show me a very simple example? "To teach is to learn twice"
I will submit a complete tutorial in next 1 or 2 days. I will completely clarify them from scratch. So, hold on just 1 or 2 days Thanx
Don't forget, that's
Persian Gulf
not Arabian gulf!
-
Hey, I am creating an alarm clock in c#. I want to create a event that calls a method to , lets say tell the user what time it is. I tried to read all tutorials on events and delegates. Still, I have no idea how to implement things. can anybody show me a very simple example? "To teach is to learn twice"