C# Tips

C# Tip Article

How to hide form when button is clicked

Question

I want to capture the entire screen from my winform application.

I have a button for screen capture. When the button is clicked, how can I hide my application form?
I do not want to include my form in the screen capture...

Tip

You can minimize your form when the button is clicked. But the better way is you can hide the application form by setting Form.Opacity property to zero. In this Opacity case, you will need to revert opacity to 100 after finishing screen capture. Otherwise, there is no easy way to see your form again.

Answer

Here is a code example of hiding the form by setting form's Opacity property.

private void button1_Click(object sender, EventArgs e)
{
    this.Opacity = 0;

    // Do something here
    Thread.Sleep(5000);

    this.Opacity = 100;
}