以下是我的解决方案:
声明此结构以存储工具栏的设置:
[Serializable]
public struct ToolStripSettings
{
public bool Visible;
public Point Location;
}
要保存的代码
// save toolbar settings
List<ToolStripSettings> toolSettings = new List<ToolStripSettings>();
// mToolbars is initialized in the constructor to contain all of your toolbar members
// you could also probably populate it with reflection
foreach (ToolStrip ts in mToolbars)
{
ToolStripSettings tss = new ToolStripSettings();
tss.Visible = ts.Visible;
tss.Location = ts.Location;
toolSettings.Add(tss);
}
// serialize the toolSettings list wherever you keep the
// rest of your user-specific settings
要还原的代码
// Load toolstrip settings, if any
if (/*deserialized storage location*/ != null)
{
for (int i = 0; i < mToolbars.Length; i++)
{
mToolbars[i].Visible = /*deserialized storage location*/[i].Visible;
mToolbars[i].Location = /*deserialized storage location*/[i].Location;
}
}