G
Guest
I'm writing an app that has a main form where, upon user request, must load a
new form (which will act as a modal dialog). In the new form, the user does
a few things, and then when they are finished, they are returned to the main
form with a result (similar to a DialogResult). This will occur several
times. I've seen many posts about similar actions and I've experimented with
the answers given. However, I can't find a solution that fits my problem.
I'm using the OnLoad event for my main form to hook up events and set up the
2D mapping control. However, I have a flag that only allows the OnLoad
events to occur the very first time the Dialog Loads (not sure that's a good
idea):
private void mainForm_OnLoad(...)
{
if (firstTime)
{
...Initialize
}
}
The user presses a button on the main form, which calls a private method
which loads the secondary form like this:
private void Launch()
{
this.Text = "";
this.Hide(); // Do I need this?
DialogResult res;
// Create new form
MyDialog dlg = new MyDialog();
if ((res = dlg.ShowDialog()) == DialogResult.OK)
{
// Update Info from User Action
UpdateInfo();
this.Text = "AppName";
this.ShowDialog();
}
else if (res == DialogResult.Cancel)
{
this.Text = "AppName";
this.ShowDialog();
}
}
It works fine the first time, however, the second time it stops at the
ShowDialog call with the following error: An unhandled exception of type
'System.ArgumentException' occurred in System.Windows.Forms.dll
Anyone know why that would happen (or need more information to help figure
it out)??
Thanks
-G
new form (which will act as a modal dialog). In the new form, the user does
a few things, and then when they are finished, they are returned to the main
form with a result (similar to a DialogResult). This will occur several
times. I've seen many posts about similar actions and I've experimented with
the answers given. However, I can't find a solution that fits my problem.
I'm using the OnLoad event for my main form to hook up events and set up the
2D mapping control. However, I have a flag that only allows the OnLoad
events to occur the very first time the Dialog Loads (not sure that's a good
idea):
private void mainForm_OnLoad(...)
{
if (firstTime)
{
...Initialize
}
}
The user presses a button on the main form, which calls a private method
which loads the secondary form like this:
private void Launch()
{
this.Text = "";
this.Hide(); // Do I need this?
DialogResult res;
// Create new form
MyDialog dlg = new MyDialog();
if ((res = dlg.ShowDialog()) == DialogResult.OK)
{
// Update Info from User Action
UpdateInfo();
this.Text = "AppName";
this.ShowDialog();
}
else if (res == DialogResult.Cancel)
{
this.Text = "AppName";
this.ShowDialog();
}
}
It works fine the first time, however, the second time it stops at the
ShowDialog call with the following error: An unhandled exception of type
'System.ArgumentException' occurred in System.Windows.Forms.dll
Anyone know why that would happen (or need more information to help figure
it out)??
Thanks
-G