Get event source from event arguments : Generic Event « GUI Windows Forms « C# / CSharp Tutorial






using System; 
using System.Windows.Forms; 
using System.Drawing; 
 
class GetEventSourceFromEventArguments : Form { 
  Button MyButton = new Button(); 
 
  public GetEventSourceFromEventArguments() { 
    Text = "Respond to a Button"; 
 
    MyButton = new Button(); 
    MyButton.Text = "Press Here"; 
    MyButton.Location = new Point(100, 200); 
 
    // Add button event handler to list. 
    MyButton.Click += MyButtonClick; 
 
    Controls.Add(MyButton); 
  }   
 
  [STAThread] 
  public static void Main() { 
    GetEventSourceFromEventArguments skel = new GetEventSourceFromEventArguments(); 
 
    Application.Run(skel); 
  } 
 
  // Handler for MyButton. 
  protected void MyButtonClick(object who, EventArgs e) { 
      Button b = (Button) who;  
      
      if(b.Top == 200)  
        b.Location = new Point(10, 10);  
      else  
        b.Location = new Point(100, 200); 
  } 
}








23.66.Generic Event
23.66.1.Get event source from event arguments
23.66.2.Generic events