- Back to Home »
- Windows Applications »
- Button
Posted by :
Sudhir Chekuri
Monday, 15 February 2016
It is used to execute when button is clicked.
Default event is Click.
To show message box on button click with text as Hello world:
Example for other events like MouseEnter and MouseLeave
Default event is Click.
To show message box on button click with text as Hello world:
private void
button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello world");
}
To change the text on the button:
private void
button1_Click(object sender, EventArgs e)
{
button1.Text = "Click
here";
}
To make button invisible:
private void button1_Click(object sender, EventArgs e)
{
button1.Visible =false;
}
We
can also use other events of button like MouseEnter and MouseLeave.
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.Text = "Mouse
entered";
}
private void button1_MouseLeave(object
sender, EventArgs e)
{
button1.Text = "Mouse
left";
}