문제

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