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:

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.

Example for other events 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";

        }

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -