Материал из .Net Framework эксперт
UI event
using System;
public class UIEvent : EventArgs
{
public UIEvent( string filename ) {
this.filename = filename;
}
private string filename;
public string Filename {
get { return filename; }
}
}
public class MyUI
{
public event EventHandler<UIEvent> PlayEvent;
public void UserPressedPlay() {
OnPlay();
}
protected virtual void OnPlay() {
EventHandler<UIEvent> localHandler = PlayEvent;
if( localHandler != null ) {
localHandler( this, new UIEvent("somefile.wav") );
}
}
}
public class MainClass
{
public static void Main() {
MyUI ui = new MyUI();
ui.PlayEvent += PlaySomething;
}
private static void PlaySomething( object source, UIEvent args ) {
Console.WriteLine("Play the file");
}
}