button.Click += new EventHandler(buttonsLive_Click);
private void buttonsLive_Click(object sender, System.EventArgs e) { // récupération du bouton ayant declencher l'event Button button = (Button)sender; // code de gestion des clics sur les boutons "live" ;) }
private void Form1_Load(object sender, EventArgs e) { Button btn = new Button() ; btn.Location = new System.Drawing.Point(20, 20); btn.Name = "btn"; btn.Size = new System.Drawing.Size(200, 25); btn.Text = "The button"; btn.Click += new System.EventHandler(btn_Click); this.Controls.Add(btn); } private void btn_Click(object sender, EventArgs e) { MessageBox.Show("bouton cliqué"); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionArrayList liste = (ArrayList)buttonClique.Tag;
object controle = liste[0]; if ( controle.GetType() == typeof(Button) ) { // c'est un bouton } else if ( controle.GetType() == typeof(Label) ) { // c'est un Label } ...
monContrôle.méthode() ....
object controle = liste[0]; if ( controle.GetType() == typeof(Button) ) { // c'est un bouton Button bouton = (Button)controle; bouton.PerformClick(); // bon ok aucun interet mais j'avais pas d'autre idée ^^ } else if ( controle.GetType() == typeof(Label) ) { // c'est un Label Label label = (Label)controle; label.Text = "Cool"; }