Unable to display form

  • Thread starter Thread starter OutdoorGuy
  • Start date Start date
O

OutdoorGuy

Greetings,

I have a "newbie" question related to forms. I am attempting to use the
code below to open up another form when the user presses the "OK" button
(after making the appropriate selection from a combo box). However, I
am receiving an error at the following line of code:

TestNumber.ActiveForm.Show();

"TestNumber" is the name of the second form that I want to display. The
code for this routine is below:

private void btnOK_Click(object sender, System.EventArgs e)
{
string strChoice = this.cboChoice.Text;
switch (strChoice)
{
case "For Loop":
TestNumber.ActiveForm.Show(); <-- Error occurs here
break;
case "While Loop":
...
break;
}
}

Any ideas as to what I am doing wrong?

Thanks in advance!
 
hi

what error are you getting?

AT compile or runtime?

it should be enough to use TestForm.Show();

btw, TestNumber is an instance variable that you created previously right?
it not the name of the class ?

chgeers,
 
Hi. Thanks for the response. I finally got it working. I failed to
instantiate the form. Adding the code below resolved the issue.

TestNumber ForLoopForm = new TestNumber();
ForLoopForm.Show();

Thanks again.
 
Back
Top