Question

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?

Était-ce utile?

La solution

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

Autres conseils

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();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top