Button.PerformClick Method
.NET Framework 3.5
Generates a Click event for a button.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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; }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.