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 ()
public final void PerformClick ()
public final function PerformClick ()
Not applicable.

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;
 }
 

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

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft