M
MFRASER
I have a form where I dynamically add a control to a panel based on a menu
selection.
Problem is that if I attempt to close the form after changing the control
the form does not close
Here is my code
This function adds the control and then at close I have tried the following
this.close(); //doesn't work
this.controls.clear()
this.close(); //doesn't work
/// <summary>
/// Convenience method for setting main control
/// </summary>
/// <param name="Testcontrol"></param>
public void SetMainControl(Control Testcontrol)
{
string Key = Testcontrol.GetType().ToString();
for(int i = StudyViewer_Fill_Panel.Controls.Count - 1; i >= 0; i--)
{
//Remove existing chart
if(StudyViewer_Fill_Panel.Controls.GetType() == Testcontrol.GetType())
{
StudyViewer_Fill_Panel.Controls.RemoveAt(i);
}
else
{
StudyViewer_Fill_Panel.Controls.Hide();
}
}
StudyViewer_Fill_Panel.Controls[StudyViewer_Fill_Panel.Controls.Count -
1].Hide();
StudyViewer_Fill_Panel.Controls.Add(Testcontrol);
Testcontrol.Dock = DockStyle.Fill;
}
selection.
Problem is that if I attempt to close the form after changing the control
the form does not close
Here is my code
This function adds the control and then at close I have tried the following
this.close(); //doesn't work
this.controls.clear()
this.close(); //doesn't work
/// <summary>
/// Convenience method for setting main control
/// </summary>
/// <param name="Testcontrol"></param>
public void SetMainControl(Control Testcontrol)
{
string Key = Testcontrol.GetType().ToString();
for(int i = StudyViewer_Fill_Panel.Controls.Count - 1; i >= 0; i--)
{
//Remove existing chart
if(StudyViewer_Fill_Panel.Controls.GetType() == Testcontrol.GetType())
{
StudyViewer_Fill_Panel.Controls.RemoveAt(i);
}
else
{
StudyViewer_Fill_Panel.Controls.Hide();
}
}
StudyViewer_Fill_Panel.Controls[StudyViewer_Fill_Panel.Controls.Count -
1].Hide();
StudyViewer_Fill_Panel.Controls.Add(Testcontrol);
Testcontrol.Dock = DockStyle.Fill;
}