代码之家  ›  专栏  ›  技术社区  ›  Nick

ToolStripManager不工作

  •  2
  • Nick  · 技术社区  · 17 年前

    ToolStripManager彻底崩溃了。LoadSettings没有任何作用……显然,我不是唯一一个有这个问题的人:

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/656f5332-610d-42c3-ae2d-0ffb84a74b34/

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=128042

    1 回复  |  直到 17 年前
        1
  •  0
  •   Nick    17 年前

    以下是我的解决方案:

    声明此结构以存储工具栏的设置:

    [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;
        }
    }
    
    推荐文章