Search code examples
c#winformstoolstrip

ToolStripManager not restoring Location of Toolstrips


ToolStripManager does not restore my Toolstrips to the previous locations as expected. I created a very simple app to demonstrate. I contains 4 movable Toolstrips in a ToolStrip Container. I move the toolstrips to order them as 4-3-2-1 from top to bottom (Figure A). Then close the app. When I reopen it they are ordered as in Figure B.

Here is the simple code. I have verified that the Key used in the LoadSettings and SaveSettings method calls is the same string.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZT2
{
    public partial class Form1 : Form
    {
        string keyName = "abc";
        public Form1()
        {
            InitializeComponent();
            keyName = Application.ProductName + this.Name + "xyz";
            ToolStripManager.LoadSettings(this, keyName);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            ToolStripManager.SaveSettings(this, keyName);
        }
    }
}

Figure A Before closing form

Figure B Reopened form

Visual Studio 2010 - C# .Net 4 Client Profile


Solution

  • Sorry was to quick...

    You will have to save it somewhere in the configuration file or some other location and check those values every time it is shown.

    Check this codesnippet out

    CODESNIPPET