Freigeben über


Button.PerformClick-Methode

Generiert ein Click-Ereignis für eine Schaltfläche.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Sub PerformClick
'Usage
Dim instance As Button

instance.PerformClick
public void PerformClick ()
public:
virtual void PerformClick () sealed
public final void PerformClick ()
public final function PerformClick ()

Hinweise

Diese Methode kann aufgerufen werden, um das Click-Ereignis auszulösen.

Beispiel

Im folgenden Codebeispiel wird ein Click-Ereignis von Button für abwechselnde Click-Ereignisse einer anderen Schaltfläche generiert. In diesem Code wird davon ausgegangen, dass zwei Button-Steuerelemente in einem Formular instanziiert wurden und eine Membervariable mit der Bezeichnung myVar als 32-Bit-Ganzzahl mit Vorzeichen innerhalb der Klasse deklariert wurde.

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 'button1_Click
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:
   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;
} //button1_Click
protected function button1_Click (sender : Object, e : EventArgs)
 {
    // 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;
 }
 

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Button-Klasse
Button-Member
System.Windows.Forms-Namespace
Click