Generic event for a Label : Label « GUI Windows Forms « C# / CSharp Tutorial






Generic event for a Label
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class LabelWithGenericEvent : System.Windows.Forms.Form
{
  private System.Windows.Forms.Label lblTitle;

  public LabelWithGenericEvent()
  {
    InitializeComponent();
  }

  private void InitializeComponent()
  {
    this.lblTitle = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // lblTitle
    // 
    this.lblTitle.Location = new System.Drawing.Point(40, 24);
    this.lblTitle.Name = "lblTitle";
    this.lblTitle.Size = new System.Drawing.Size(150, 25);
    this.lblTitle.TabIndex = 0;
    this.lblTitle.Text = "Events Demonstrator";
    this.lblTitle.Click += new System.EventHandler(this.GenericEventHandler);
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(242, 173);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {  this.lblTitle});
    this.ResumeLayout(false);

  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new LabelWithGenericEvent());
  }
  private void GenericEventHandler(object sender, EventArgs e)
  {
    MessageBox.Show("Generic event handler","Event Demo");
  }
}








23.7.Label
23.7.1.Label Text ChangeLabel Text Change
23.7.2.Add image to LabelAdd image to Label
23.7.3.Add Image in an ImageList to a LabelAdd Image in an ImageList to a Label
23.7.4.Generic event for a LabelGeneric event for a Label