I have a button that on click I would like to be disabled and it’s background image to be changed to null here is the code I have that happens on button click
private void levelOne1001_Click(object sender, EventArgs e)
{
levelOne1001.Enabled = false;
levelOne1001.BackgroundImage = null;
scoreClass.genRandomNumber(100);
scoreClass.valOfQuestion = 100;
q1001 = true;
openQuestionForm();
}
And here is the code from openQuestionForm();
private void openQuestionForm()
{
QuestionForm qForm = new QuestionForm();
scoreClass.iCount++;
qForm.Show();
this.Hide();
}
And here is where I call this form back up
Level1Form l1Form = new Level1Form();
l1Form.Show();
How the process works is Button on Original form is clicked goes to a Question form, button on Question form is clicked it goes back to Original Form. But when I go back to the original form the button is still enabled and the image is still there. Is there any way to fix this?
EDIT: Forgot to say this was in WinForms
You are instantiating a new Level1Form, so it’s returning to its default state, causing the button to return to its default state. There are a few possible approaches:
Add a parameter to Level1Form’s constructor that indicates what state the button should be in, something like
Or, grab the same form again and reuse it. You will need to keep a reference to it somewhere and tell it to show itself again. Alternately, you can grab it out of
Application.OpenForms