Csharp/C Sharp by API/System/EventArgs
Версия от 15:31, 26 мая 2010; (обсуждение)
extends EventArgs
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");
}
}