Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Form instead of closing it [duplicate]

Tags:

c#

.net

winforms

try to hide form instead of closing it, using

    private void Playlist_FormClosed(object sender, FormClosedEventArgs e)
    {
        if (e.CloseReason == CloseReason.FormOwnerClosing) //if closed by aplication
        {
            this.Close();
        }
        if (e.CloseReason == CloseReason.UserClosing) //if closed by user
        {
            this.Hide();
        }
    }

but it's still close it, if User click Close.

like image 696
hbk Avatar asked Dec 15 '25 12:12

hbk


1 Answers

Use FormClosing instead of FormClosed. There you can do e.Cancel = true; to achieve what you need. The problem is that the form is already Closed by the time FormClosed event occurs, so Hide() won't do any good and you won't be able to use this object in the future, if you try it with FormClosed event.

like image 149
dotNET Avatar answered Dec 17 '25 02:12

dotNET



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!