What I'm trying to do is get user input from a form (IncomeForm
) by using a textbox (TextBoxIncomePrice
) and after pressing the button (ButtonConfirmIncome
), the LabelIncome
label in the form MainPage
should change to the value input by the user.
Everything works as intented, except for when I try to reopen the IncomeForm
by clicking the AddIncomeButton
. I get the error shown in the title. It should be able to reopen and accept a new value no matter how many times you close the IncomeForm
.
Main Form (MainPage):
IncomeForm incomeForm = new IncomeForm();
private void incomeForm_FormClosed(object sender, FormClosedEventArgs e)
{
LabelIncome.Text = incomeForm.TextBoxIncomePrice.Text;
}
private void AddIncomeButton_Click(object sender, EventArgs e)
{
incomeForm.FormClosed += new FormClosedEventHandler(incomeForm_FormClosed);
incomeForm.Show();
}
Add Income Form (IncomeForm):
private void ButtonConfirmIncome_Click(object sender, EventArgs e)
{
this.Close();
}