19

MDIParentフォームを使用しています。私がその子を閉じると、子のオブジェクトは破棄されます。子の可視性を破棄する代わりにfalseに設定する方法はありますか?

4

5 に答える 5

43

デフォルトでは、フォームを閉じると破棄されます。Closingそれを防ぐには、イベントをオーバーライドする必要があります。次に例を示します。

// 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.
}
于 2011-05-19T14:51:46.617 に答える
4

close イベントをキャンセルして、代わりに非表示にすることができます。

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        e.Cancel = true;
        this.Hide();
    }
于 2011-05-19T15:00:45.447 に答える
2

Yes. You can call the form's "Hide" method.

You can also override OnClosed and not call its base implementation; HOWEVER, when you DO want to dispose of the form, this may get in your way.

于 2011-05-19T14:49:54.187 に答える
0

Sure, you can cancel the close and hide it. It doesn't seem like a good thing to do, but you definitely can.

See Form.FormClosing Event (MSDN).

于 2011-05-19T14:50:34.187 に答える
0
    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;
}
于 2017-06-23T08:13:08.737 に答える