Csharp/CSharp Tutorial/GUI Windows Forms/EventArgs — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:31, 26 мая 2010
UI event
<source lang="csharp">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"); }
}</source>