delegate void SpeakDelegate(string message); private void Speak(string message) { Debug.WriteLine(message); } private void StarSpeak(string message) { Debug.WriteLine("★" + message); } event SpeakDelegate SpeakEventHandler; private void event_Clicked(object sender, RoutedEventArgs e) { SpeakEventHandler += Speak; SpeakEventHandler += StarSpeak; SpeakEventHandler("Hello World"); }
Hello World ★Hello World
public class SpeakEventArgs :EventArgs { public string Message {get; set; } } public void OnSpeak(object sender, SpeakEventArgs e) { Debug.WriteLine(e.Message); } public void OnStarSpeak(object sender, SpeakEventArgs e) { Debug.WriteLine("★" + e.Message); } delegate void SpeakHandler(object sender, SpeakEventArgs e); event SpeakHandler TestSpeakHandler; private void event2_Clicked(object sender, RoutedEventArgs e) { TestSpeakHandler += OnSpeak; TestSpeakHandler += OnStarSpeak; TestSpeakHandler(this, new SpeakEventArgs() { Message = "Hello World" }); }
Hello World ★Hello World
event EventHandler FixSpeakHandler; public void OnFixSpeak(object sender, EventArgs e) { Debug.WriteLine("固定メッセージ"); } public void OnFixStarSpeak(object sender, EventArgs e) { Debug.WriteLine("★固定メッセージ"); } private void event3_Clicked(object sender, RoutedEventArgs e) { FixSpeakHandler += OnFixSpeak; FixSpeakHandler += OnFixStarSpeak; FixSpeakHandler(this, new EventArgs()); }
固定メッセージ ★固定メッセージ