Problem with accessing Forms - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem with accessing Forms

pieshoppieshop Posts: 4Member
Hi,

I have an app that will use multiple forms, upon the program running the initial form, I want to to create a 2nd form, but not display it until a user clicks on a button on Form1. Sounds simple enough? Where I'm having problems is with the compiler deciding that this other form doesn't exist in the current context.

My code...
[code]namespace MyProgram
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
MyFormClass MyForm = new MyFormClass();
}

private void buttonCardIndex_Click(object sender, EventArgs e)
{
MyForm.Show();
}
}
}[/code]

The compiler tells me that MyForm.Show() [italic]does not exist in the current context[/italic], but it must do because if I put this line underneath the line that creates it, it works. What I don't understand is why I can't reference it from the button click as the form must exist because it's created when Form1 is run.

I'm guessing I'm doing something silly, but I can't work out what.

Thanks
Sign In or Register to comment.