I'm trying to set the SplitContainer.SplitterDistance from inside a function called by the Onload event of a UserControl. The problem is that the distance adds a couple of extra pixels to the value I assign. I'm loading the value from XML but I have verified that the XML works.
As you can see from my code i set this property on two seperate splitters. "splitter" is vertical and sets just fine but "spitcontainer1" is horizontal and has the problem.
Here's my code:
private void frmShell_Load(object sender, EventArgs e)
{
try
{
if (File.Exists(Application.StartupPath + "\\ApplicationSettings.xml"))
{
XmlTextReader XMLreader = new XmlTextReader(Application.StartupPath + "\\ApplicationSettings.xml");
XMLreader.WhitespaceHandling = WhitespaceHandling.None;
XMLreader.MoveToContent();
do
{
switch (XMLreader.Name)
{
case "root":
break;
case "outputWindow":
splitContainer1.Panel2Collapsed = !Convert.ToBoolean(XMLreader.GetAttribute("visible"));
splitContainer1.SplitterDistance = Convert.ToInt32(XMLreader.GetAttribute("location"));
outputWindowToolStripMenuItem.Checked = !splitContainer1.Panel2Collapsed;
break;
case "projectWindow":
splitter.Panel1Collapsed = !Convert.ToBoolean(XMLreader.GetAttribute("visible"));
splitter.SplitterDistance = Convert.ToInt32(XMLreader.GetAttribute("location"));
projectViewerToolStripMenuItem.Checked = !splitter.Panel1Collapsed;
break;
default:
break;
}
} while (XMLreader.Read());
}
}
catch (Exception arg)
{
}
}
Thank you for your help!

SplitContainer.SplitterDistance
3js
When your UserControl is loaded, your SplitContainer is probably resized along with the UserControl which contains it. Setting the FixedPanel property of the SplitContainer should fix it.