Gestion des événements d’un bouton

Author:

Gestion,des,événements,d'un,bouton
{filelink=14650}

using System;
using System.Windows.Forms;
using System.Drawing; 

public class TextBouton : Form {
  Button textBouton = new Button(); 

  public TextBouton() {
    Text = "Gestion Evénement des Boutons"; 

    textBouton = new Button();
    textBouton.Text = "Cliquez Ici";
    textBouton.Location = new Point(100, 200);
    textBouton.Size = new Size(60, 30);
    // Ajout un écouteur de gestion des événements à notre bouton
    textBouton.Click += new EventHandler(textBoutonClick); 

    Controls.Add(textBouton);
  }   

  [STAThread]
  public static void Main() {
    TextBouton test = new TextBouton(); 

    Application.Run(test);
  } 

  // élargir et déplacer le bouton.
  protected void textBoutonClick(object who, EventArgs e)
  { 

      if (textBouton.Width == 60)
      textBouton.Size = new Size(180, 30);
  else
      textBouton.Size = new Size(60, 30);
    if(textBouton.Top == 200)
      textBouton.Location = new Point(10, 10);
    else
      textBouton.Location = new Point(100, 200);

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *