3

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.

dotNET
  • 33,414
  • 24
  • 162
  • 251
hbk
  • 10,908
  • 11
  • 91
  • 124
  • 2
    The event you're capturing is `Closed`. Try handling `Closing` instead, intercept it, cancel it, and hide instead of closing. – Eli Gassert Sep 20 '13 at 17:00

1 Answers1

13

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.

dotNET
  • 33,414
  • 24
  • 162
  • 251
  • 2
    Thanks - now it's work - use `FormClosing ` - during closing prosess instead of `FormClosed` - after closing process, noted – hbk Sep 20 '13 at 17:03