.NET Framework Class Library
Button.PerformClick Method
Generates a Click event for a button.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
Visual Basic (Declaration)
Public Sub PerformClick
Visual Basic (Usage)
Dim instance As Button instance.PerformClick
C#
public void PerformClick ()
C++
public: virtual void PerformClick () sealed
J#
public final void PerformClick ()
JScript
public final function PerformClick ()
Remarks
This method can be called to raise the Click event.
Example
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.
Visual Basic
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
C#
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; }
C++
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++; }
J#
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
JScript
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; }
Platforms
Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Version Information
.NET Framework
Supported in: 2.0, 1.1, 1.0See Also
