UI event : EventArgs « GUI Windows Forms « C# / CSharp Tutorial






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");
    }

}








23.65.EventArgs
23.65.1.UI event