0

Hey guys,

I want my form to hide instead to close by clicking on the red X button. Because when it's closed the form is deleted.
I searched a lot to find a good solution, but nothing works.
Many people wrote that following code:

private void Form1_OnClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

would solve the problem. I tried it. My Form is not hiding. I don't know what I did wrong.
I would be very happy if you could help me.

Thanks :)

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

You forgot to manually bind the form event to that method.. is it being fired?

add this.FormClosing += new FormClosingEventHandler(Form1_OnClosing);

in your form load method

0

It works, you are a genius :)

I'm a newbie therefore I don't know such things.
Thank you so much :)

0

lol,
he is not a genious. He only knows more.

jfarrugia btw, next time what is the code, you have to put it into code brackets!
I hope you understand (forum rules).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.