Button.PerformClick Metoda
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Click Generuje zdarzenie dla przycisku.
public:
virtual void PerformClick();
public void PerformClick();
abstract member PerformClick : unit -> unit
override this.PerformClick : unit -> unit
Public Sub PerformClick ()
Implementuje
Przykłady
Poniższy przykład kodu generuje Click zdarzenie Button na przemienne Click zdarzenia innego przycisku. W tym kodzie założono, że w formularzu zostały utworzone dwie Button kontrolki i że zmienna składowa o nazwie myVar została zadeklarowana jako 32-bitowa liczba całkowita podpisana w klasie.
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;
}
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
Uwagi
Tę metodę Click można wywołać, aby zgłosić zdarzenie.