static public void SplitterDistance(this SplitContainer sp, double value) // set the splitter distance from a double value.. safe from exceptions. { if (!double.IsNaN(value) && !double.IsInfinity(value)) { int a = (sp.Orientation == Orientation.Vertical) ? sp.Width : sp.Height; int curDist = sp.SplitterDistance; //System.Diagnostics.Debug.WriteLine("Size is " + a); if (a == 0) // Sometimes the size is {0,0} if minimized. Calc dimension from the inner panels. See issue #1508. { a = (sp.Orientation == Orientation.Vertical ? sp.Panel1.Width + sp.Panel2.Width : sp.Panel1.Height + sp.Panel2.Height) + sp.SplitterWidth; } //System.Diagnostics.Debug.WriteLine("Now Size is " + a + " " + sp.Panel1MinSize + " " + (sp.Height - sp.Panel2MinSize)); try { // protect it against excepting because even with the careful protection above and below, it can still mess up if the window is completely small sp.SplitterDistance = Math.Min(Math.Max((int)Math.Round(a * value), sp.Panel1MinSize), a - sp.Panel2MinSize); } catch { System.Diagnostics.Debug.WriteLine("Splitter failed to set in " + sp.GetType().Name); } //System.Diagnostics.Debug.WriteLine($"SplitContainer {sp.Name} {sp.DisplayRectangle} {sp.Panel1MinSize}-{sp.Panel2MinSize} Set SplitterDistance to {value:N2} (was {curDist}, now {sp.SplitterDistance})"); } else { System.Diagnostics.Debug.WriteLine($"SplitContainer {sp.Name} {sp.DisplayRectangle} {sp.Panel1MinSize}-{sp.Panel2MinSize} Set SplitterDistance attempted with unsupported value ({value})"); } }
static string GetSplitContainerState(SplitContainer splitContainer) { Hashtable table = new Hashtable(); table["ratio"] = splitContainer.GetSplitterState().ToString(); table["orientation"] = splitContainer.Orientation == Orientation.Vertical ? "v" : "h"; return(splitContainer.GetType().ToString() + ":" + StringUtil.BuildParameterString(table)); }
static string GetSplitContainerState(SplitContainer splitContainer) { return(splitContainer.GetType().ToString() + ":" + GuiUtil.GetSplitterState(splitContainer).ToString()); }