Export (0) Print
Expand All

Button.PerformClick Method

Generates a Click event for a button.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void PerformClick()

Implements

IButtonControl.PerformClick()

This method can be called to raise the Click event.

The following code example generates a Click event of a Button on alternating Click events of another button. 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 = myVar + 1;
 }
 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft