Get event name for sender : UI Event « Event « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Event » UI EventScreenshots 
Get event name for sender
Get event name for sender


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
   Label Label1;
   TextBox TextBox1;
   Button Button1;

  public Form1()
  {
        InitializeComponent();
  }
   private void ctrlClick(System.Object sender, EventArgs e)
   {
     Control ctrl = (Control)sender;
     MessageBox.Show("You clicked: " + ctrl.Name);
   }

  private void InitializeComponent()
  {
    this.Label1 = new System.Windows.Forms.Label();
    this.TextBox1 = new System.Windows.Forms.TextBox();
    this.Button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // Label1
    // 
    this.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.Label1.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Label1.Location = new System.Drawing.Point(1497);
    this.Label1.Name = "Label1";
    this.Label1.Size = new System.Drawing.Size(11224);
    this.Label1.TabIndex = 8;
    this.Label1.Text = "Label1";
    this.Label1.Click += new System.EventHandler(this.ctrlClick);
    // 
    // TextBox1
    // 
    this.TextBox1.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.TextBox1.Location = new System.Drawing.Point(1261);
    this.TextBox1.Name = "TextBox1";
    this.TextBox1.Size = new System.Drawing.Size(15621);
    this.TextBox1.TabIndex = 7;
    this.TextBox1.Text = "TextBox1";
    this.TextBox1.Click += new System.EventHandler(this.ctrlClick);
    // 
    // Button1
    // 
    this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.Button1.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Button1.Location = new System.Drawing.Point(1221);
    this.Button1.Name = "Button1";
    this.Button1.Size = new System.Drawing.Size(9628);
    this.Button1.TabIndex = 6;
    this.Button1.Text = "Button1";
    this.Button1.Click += new System.EventHandler(this.ctrlClick);
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(367281);
    this.Controls.Add(this.Label1);
    this.Controls.Add(this.TextBox1);
    this.Controls.Add(this.Button1);
    this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "Form1";
    this.Text = "Control Medley";
    this.ResumeLayout(false);
    this.PerformLayout();

  }


  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}


           
       
Related examples in the same category
1.Add mouse click event to TextBox
2.Add mouse click event to a LabelAdd mouse click event to a Label
3.Event TrackerEvent Tracker
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.