First declare a delegate:
private delegate void AudioIsPlayingHandler(MediaElement elem);
Then declare an event:
private event AudioIsPlaingHandler OnAudioIsPlaying;
Somewhere, the class throws the event:
if (OnAudioIsPlaying != null)
OnAudioIsPlaying(elem); // Raise the event and pass some data
Now, in a class that has an instance of the previous class:
First, attach to the event in obj A, an instance of the previous class:
A.OnAudioIsPlaying += new System.EventHandler(A_OnAudioIsPlaying);
Then, in the handler function:
private void A_OnAudioIsPlaying(MediaElement elem)
{
// Do something with the data received
}
Finally, check this out for a lot more details:
Visual Studio Developer Center - Events Tutorial
No comments:
Post a Comment