Pregunta

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?

¿Fue útil?

Solución

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

Otros consejos

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();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top