public static List <Control> injectControl(this Control controlToWrap, Control controlToInject, AnchorStyles location, int splitterDistance, bool border3D, string title_1, string title_2) { try { if (controlToWrap == null || controlToInject == null) { return(new List <Control>()); } return((List <Control>)controlToWrap.invokeOnThread(() => { var childControls = new List <Control>(); var parentControl = controlToWrap.parent(); if (parentControl.isNull()) //means we will need to add to the current one (or the parent control is a a Form) { childControls.add(controlToWrap.controls()); parentControl = controlToWrap; } else { childControls.add(controlToWrap); } foreach (var childControl in childControls) { parentControl.remove(childControl); } var controls = new List <Control>(); SplitContainer splitContainer = parentControl.add_SplitContainer(); splitContainer.fill(); if (border3D) { splitContainer.border3D(); } switch (location) { case AnchorStyles.Top: case AnchorStyles.Left: splitContainer.Panel1.add(controlToInject); splitContainer.Panel2.Controls.AddRange(childControls.ToArray()); splitContainer.FixedPanel = FixedPanel.Panel1; try { //if (splitterDistance > -1 && splitterDistance > splitContainer.Panel1MinSize && // splitterDistance < ( splitContainer.Width - splitContainer.Panel2MinSize)) if (splitterDistance > 0) { splitContainer.SplitterDistance = splitterDistance; } } catch (Exception ex) { "Could not set Splitter Distance to value {0} : {1}".format(splitterDistance, ex.Message).error(); } splitContainer.Orientation = (location == AnchorStyles.Top) ? Orientation.Horizontal : Orientation.Vertical; break; case AnchorStyles.Bottom: case AnchorStyles.Right: splitContainer.Panel1.Controls.AddRange(childControls.ToArray()); splitContainer.Panel2.add(controlToInject); //splitContainer.Panel1.add(controlToWrap); //splitContainer.Panel2.add(controlToInject); splitContainer.Orientation = (location == AnchorStyles.Bottom) ? Orientation.Horizontal : Orientation.Vertical; splitContainer.FixedPanel = FixedPanel.Panel2; if (splitterDistance > -1) { var newSplitterDistance = (location == AnchorStyles.Bottom) ? splitContainer.Height - splitterDistance : splitContainer.Width - splitterDistance; if (newSplitterDistance > 0) { splitContainer.SplitterDistance = newSplitterDistance; } else { "Could not set Splitter Distance since it was a negative value: {0}".format(newSplitterDistance).error(); } } break; case AnchorStyles.None: PublicDI.log.error("in injectControl the location provided was AnchorStyles.None"); break; } controls.add(splitContainer) .add(controlToWrap) .add(controlToInject); return controls; })); } catch (Exception ex) { PublicDI.log.ex(ex, "in injectControl"); return(null); } }