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

后端 未结 5 554
南方客
南方客 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:43

        void SaveInfo()
    {
    blnCanCloseForm = false;
    Vosol[] vs = getAdd2DBVosol();
    if (DGError.RowCount > 0)
    return;
    
    Thread myThread = new Thread(() =>
    {
    this.Invoke((MethodInvoker)delegate {
        picLoad.Visible = true;
        lblProcces.Text = "Saving ...";
    });
    int intError = setAdd2DBVsosol(vs);
    Action action = (() =>
    {
        if (intError > 0)
        {
            objVosolError = objVosolError.Where(c => c != null).ToArray();
            DGError.DataSource = objVosolError;// dtErrorDup.DefaultView;
            DGError.Refresh();
            DGError.Show();
            lblMSG.Text = "Check Errors...";
        }
        else
        {
            MessageBox.Show("Saved All Records...");
            blnCanCloseForm = true;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    
    });
    this.Invoke((MethodInvoker)delegate {
        picLoad.Visible = false;
        lblProcces.Text = "";
    });
    this.BeginInvoke(action);
    });
    myThread.Start();
    }
    
    void frmExcellImportInfo_FormClosing(object s, FormClosingEventArgs e)
    {
        if (!blnCanCloseForm)
            e.Cancel = true;
    }
    

提交回复
热议问题