I encountered a problem while playing with the program.
The buttons all work and open the forms as they should, however, when i close a form I opened and then click to open it again, i get an error.
I checked the Try It from Lesson 9 downloaded from the Wrox site and it has the error too.
Code:
public Form1()
{
InitializeComponent();
}
//the remote forms
GettingThereForm theGettingThereForm;
GettingAroundForm theGettingAroundForm;
LodgingForm theLodgingForm;
FunStuffForm theFunStuffForm;
private void Form1_Load(object sender, EventArgs e)
{
//initialise the form variables but dont display them
theGettingThereForm = new GettingThereForm();
theGettingAroundForm = new GettingAroundForm();
theLodgingForm = new LodgingForm();
theFunStuffForm = new FunStuffForm();
}
private void btnGettingThere_Click(object sender, EventArgs e)
{
//On button Click, open the form
theGettingThereForm.Show();
}
I cant post an image of the error, but it said:
ObjectDisposedException was Unhandled
Cannot access a disposed object
Object name: GettingThereForm
Troubleshooting Tip:
Make sure you have not release a resource before attempting to use it.
What does this mean?? Is it caused by the forms being initialised outside the click handler?
Perhaps this is something that will be covered in later chapters, but I thought i should let you know about the error in case someone else wonders what is going on.