How do I prevent a form object from disposing on close?

后端 未结 5 579
南方客
南方客 2020-12-06 10:27

I am using an MDIParent Form. When I close its child, the object of the child disposes. Is there a way to set child visibility to false instead of disposing?

5条回答
  •  天命终不由人
    2020-12-06 10:41

    By default, when you close a form, it will be disposed. You have to override the Closing event to prevent it, for example:

    // Use this event handler for the FormClosing event.
    private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
    {
      this.Hide();
      e.Cancel = true; // this cancels the close event.
    }
    

提交回复
热议问题