I need to save and restore settings for certain controls on the form.
I loop through all the controls and return the one whose name matches the one I want, for example:
private static Control GetControlByName(string name, Control.ControlCollection Controls)
{
Control thisControl = null;
foreach (Control c in Controls)
{
if (c.Name == name)
{
thisControl = c;
break;
}
if (c.Controls.Count > 0)
{
thisControl = GetControlByName(name, c.Controls);
if (thisControl != null)
{
break;
}
}
}
return thisControl;
}
From this, I can determine the type of control and, therefore, the property that should be / has been saved.
This works well if the control is not one of the ToolStrip family that has been added to the toolbar. eg.
this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.lblUsername,
this.toolStripSeparator1,
this.cbxCompany});
In this case, I can see the control that interests me (cbxCompany) during debugging, but the name property does not matter, so the code does not match it.
Any suggestions on how I can get to these controls?
Cheers, Murray