Button.PerformClick Méthode

Définition

Génère un événement Click pour un bouton.Generates a Click event for a button.

public:
 virtual void PerformClick();
public void PerformClick ();
abstract member PerformClick : unit -> unit
override this.PerformClick : unit -> unit
Public Sub PerformClick ()

Implémente

Exemples

L’exemple de code suivant génère un événement Click d’un Button sur des Click des événements de remplacement d’un autre bouton.The following code example generates a Click event of a Button on alternating Click events of another button. Ce code suppose que deux contrôles Button ont été instanciés sur un formulaire et qu’une variable membre nommée myVar a été déclarée comme un entier signé 32 bits dans la classe.This code assumes that two Button controls have been instantiated on a form and that a member variable named myVar has been declared as a 32-bit signed integer within the class.

private:
   void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      // If myVar is an even number, click Button2.
      if ( myVar % 2 == 0 )
      {
         button2->PerformClick();
         // Display the status of Button2's Click event.
         MessageBox::Show( "button2 was clicked " );
      }
      else
      {
         // Display the status of Button2's Click event.
         MessageBox::Show( "button2 was NOT clicked" );
      }
      // Increment myVar.   
      myVar++;
   }
private void button1_Click (Object sender, 
                               EventArgs e)
 {
    // If myVar is an even number, click Button2.
    if(myVar %2 == 0)
    {
       button2.PerformClick();
       // Display the status of Button2's Click event.
       MessageBox.Show("button2 was clicked ");
    }
    else
    {
       // Display the status of Button2's Click event.
       MessageBox.Show("button2 was NOT clicked");
    }
    // Increment myVar.   
    myVar = myVar + 1;
 }
 
Private Sub button1_Click(sender As Object, e As EventArgs)
    ' If myVar is an even number, click Button2.
    If myVar Mod 2 = 0 Then
        button2.PerformClick()
        ' Display the status of Button2's Click event.
        MessageBox.Show("button2 was clicked ")
    Else
        ' Display the status of Button2's Click event.
        MessageBox.Show("button2 was NOT clicked")
    End If
    ' Increment myVar.   
    myVar = myVar + 1
End Sub

Remarques

Cette méthode peut être appelée pour déclencher l’événement Click.This method can be called to raise the Click event.

S’applique à

Voir aussi