dario_ramos
dario_ramos

Reputation: 7309

Split Container SplitterDistance changes without user intervention

My Winforms app saves and restores its GUI state in the database. Everything's working ok, except for a Split Container's SplitterDistance.

The value is correctly loaded and set from DB, but when I exit the app without touching the splitter, I expect it to save the same value. But it saves the initial value minus 25 pixels. If I open and close the app many times, the splitter distance decreases by 25 pixels every time.

It's not a custom control, just a plain old .NET SplitContainer. The control is only accessed programatically to load its initial SplitterDistance and save it on exit, nothing else.

How can I troubleshoot this?

UPDATE: The spl's FixedPanel property was originally set to None. Tried setting it to Panel1 and Panel2; in both cases, SplitterDistance grows 50 pixels when I save it.

Upvotes: 5

Views: 5469

Answers (4)

gurikbal singh
gurikbal singh

Reputation: 19

int splitContainery = Properties.Settings.Default.SplitterDistance;

if i could use Properties.Settings.Default.SplitterDistance so i could never use ini file for example

Upvotes: -1

Adail Retamal
Adail Retamal

Reputation: 438

I used the above response as follows (my splitter is vertical):

private void Form1_Load(object sender, EventArgs e) 
{
    int splitContainery = Properties.Settings.Default.SplitterDistance;
    if(splitContainery < splContainer.ClientSize.Width)
        splContainer.SplitterDistance = splContainer.ClientSize.Width - splitContainery;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    int splitContainery = splContainer.ClientSize.Width - splContainer.SplitterDistance;
    Properties.Settings.Default.SplitterDistance = splitContainery;
    Properties.Settings.Default.Save();            
}

I created the PropertyBinding for the splContainer.SplitterDistance, but did not bind it to the property, just to have it in the ApplicationSettings file.

Upvotes: 1

gurikbal singh
gurikbal singh

Reputation: 19

download sample application

        // my splitContainer1 is Horizontal so i used splitContainer1.ClientSize.Height 
        // if you have splitContainer1 is Vertical use splitContainer1.ClientSize.Width
        // without FixedPanel save and load """  
        // loading SplitterDistance from ini file
        int splitContainery = 0;
        splitContainery = (Win32.GetPrivateProfileInt(PluginName, "splitContainer", 0, iniFilePath));
        splitContainer1.SplitterDistance = splitContainer1.ClientSize.Height - splitContainery;

        // saving splitContainer1.SplitterDistance to ini file
        int hhkt = splitContainer1.ClientSize.Height - splitContainer1.SplitterDistance;
        Win32.WritePrivateProfileString(PluginName, "splitContainer", hhkt.ToString(), iniFilePath);

Upvotes: 2

Turbot
Turbot

Reputation: 5225

Do you have user controls inside the split container , and probably when they are all loaded it would resized along with the user controls which contain it.

To troubleshoot that, set a FixedPanel Property and observe it.

Upvotes: 2

Related Questions