سؤال

I have a button that brings up another form, but the way I do it

    hozzaadasForm HozzaadasForm;

    private void hozzaadButton_Click(object sender, EventArgs e)
    {
        HozzaadasForm = new hozzaadasForm();
        HozzaadasForm.Show();
    }

Opens a new form, everytime I click the button, I don't really want that, but if I do it like this

    hozzaadasForm HozzaadasForm = new hozzaadasForm();

    private void hozzaadButton_Click(object sender, EventArgs e)
    {
        HozzaadasForm.Show();
    }

Once I close it, I can't reopen it. (ObjectDisposedException was unhandled). What can I do so it doesn't open a new one if one is already open, but I can open one, once I close it?

هل كانت مفيدة؟

المحلول

When you close the form, instead of actually closing it, you can call Hide().

نصائح أخرى

In HozzaadasForm, subscribe to the Closing event, then cancel the close and hide the form instead:

private void HozzaadasForm_FormClosing(object sender, FormClosingEventArgs e)
{
    e.Cancel = true;

    this.Hide();
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top