Question

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

Was it helpful?

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

OTHER TIPS

Save setting on Form Closing by :

ToolStripManager.SaveSettings(this);

Load the setting in Form Load by :

ToolStripManager.LoadSettings(this);

one problem with ToolStripContainer is that you cannot just set the location of a containing ToolStrip, as the container always checks the other ToolStrips in the container.

It's working fine if you do not place the ToolStrips in the container at design time. You just need a function to initialize them once.

Another possibility is to set the parent property of each Toolstrip to null before you call the ToolStripManager.LoadSettings function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top