G
Guest
Compact Framework 2 - SP2
Setup the project...
Form1 that contains two buttons and an input panel.
Form2 that contains one label and an input panel.
Form2's constructor has an integer as an parameter. This will be the
identifier when the form shows it status message. Everytime the input panel
changes enable state the form will popup a messagebox with the id and the
panel's state.
Form1's buttons are exactly the same in that both will create a variable for
Form2 then call the ShowDialog method. The difference is that one will call
the dispose method after displaying the form.
Setup the problem...
When you click either button the Form2 will popup then you can click the OK
button. Once you click the button to close the form the messagebox will popup
and state "Form2 - 0: False". Close the messagebox. At this point I expect
the Form2 variable to be dispose and irrelevant.
Enter the problem...
Now if you click Form1's input panel you will get a message from the Form2
that states "Form2 - 0: True". At this point you shouldn't be running any
code in Form2...
Code below...
public partial class Form1 : Form
{
protected int count;
public Form1()
{
InitializeComponent();
count = 0;
}
private void button1_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2(count++);
try
{
dlg.ShowDialog();
}
finally
{
dlg.Dispose();
}
}
private void button2_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2(count++);
dlg.ShowDialog();
}
}
public partial class Form2 : Form
{
protected int _id;
public Form2(int ID)
{
InitializeComponent();
_id = ID;
label1.Text = "Form2: " + _id.ToString();
inputPanelForm2.Enabled = true;
}
private void inputPanelForm2_EnabledChanged(object sender, EventArgs
e)
{
MessageBox.Show("Form2 - " + _id.ToString() + ": " +
inputPanelForm2.Enabled.ToString());
}
private void Form2_Closing(object sender, CancelEventArgs e)
{
inputPanelForm2.Enabled = false;
}
}
Setup the project...
Form1 that contains two buttons and an input panel.
Form2 that contains one label and an input panel.
Form2's constructor has an integer as an parameter. This will be the
identifier when the form shows it status message. Everytime the input panel
changes enable state the form will popup a messagebox with the id and the
panel's state.
Form1's buttons are exactly the same in that both will create a variable for
Form2 then call the ShowDialog method. The difference is that one will call
the dispose method after displaying the form.
Setup the problem...
When you click either button the Form2 will popup then you can click the OK
button. Once you click the button to close the form the messagebox will popup
and state "Form2 - 0: False". Close the messagebox. At this point I expect
the Form2 variable to be dispose and irrelevant.
Enter the problem...
Now if you click Form1's input panel you will get a message from the Form2
that states "Form2 - 0: True". At this point you shouldn't be running any
code in Form2...
Code below...
public partial class Form1 : Form
{
protected int count;
public Form1()
{
InitializeComponent();
count = 0;
}
private void button1_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2(count++);
try
{
dlg.ShowDialog();
}
finally
{
dlg.Dispose();
}
}
private void button2_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2(count++);
dlg.ShowDialog();
}
}
public partial class Form2 : Form
{
protected int _id;
public Form2(int ID)
{
InitializeComponent();
_id = ID;
label1.Text = "Form2: " + _id.ToString();
inputPanelForm2.Enabled = true;
}
private void inputPanelForm2_EnabledChanged(object sender, EventArgs
e)
{
MessageBox.Show("Form2 - " + _id.ToString() + ": " +
inputPanelForm2.Enabled.ToString());
}
private void Form2_Closing(object sender, CancelEventArgs e)
{
inputPanelForm2.Enabled = false;
}
}