protected override void OnLayout(LayoutEventArgs levent)
{
Rectangle separatorRect = Rectangle.Empty;
// Only use layout logic if control is fully initialized or if being forced
// to allow a relayout or if in design mode.
if (IsInitialized || _forcedLayout || (DesignMode && (_drawSeparator != null)))
{
// Do we need to perform right to left layout of the control?
bool rtl = (CommonHelper.GetRightToLeftLayout(this) && (RightToLeft == RightToLeft.Yes));
// If we are zero sized then reflect that in the child panels
if (Width == 0)
{
Panel1.Size = new Size(0, Height);
Panel2.Size = new Size(0, Height);
}
else if (Height == 0)
{
Panel1.Size = new Size(Width, 0);
Panel2.Size = new Size(Width, 0);
}
else
{
// If neither panel is collapsed
if (!Collapsed)
{
// Positioning of the panels depends on the orientation
if (Orientation == Orientation.Vertical)
{
// Do we used a fixed size for the first panel?
if (FixedPanel == FixedPanel.Panel1)
{
// Set the fixed size of first panel, and fill remaining space with
// second but applying the second panel minimum size specification
Panel1.Size = new Size(_fixedDistance, Height);
Panel2.Size = new Size(Math.Max((Width - SplitterWidth - _fixedDistance), Panel2MinSize), Height);
// Positioning depends on right-to-left layout setting
if (rtl)
{
Panel1.Location = new Point(Panel2.Width + SplitterWidth, 0);
Panel2.Location = Point.Empty;
}
else
{
Panel1.Location = Point.Empty;
Panel2.Location = new Point(Panel1.Width + SplitterWidth, 0);
}
// Update the splitter distance and percentage to reflect new positions
_splitterDistance = Panel1.Width;
_splitterPercent = (double)Panel1.Width / (double)Width;
}
else if (FixedPanel == FixedPanel.Panel2)
{
// Set the fixed size of second panel, and fill remaining space with
// first but applying the first panel minimum size specification
Panel2.Size = new Size(_fixedDistance, Height);
Panel1.Size = new Size(Math.Max((Width - SplitterWidth - _fixedDistance), Panel1MinSize), Height);
// Positioning depends on right-to-left layout setting
if (rtl)
{
Panel1.Location = new Point(Panel2.Width + SplitterWidth, 0);
Panel2.Location = Point.Empty;
}
else
{
Panel1.Location = Point.Empty;
Panel2.Location = new Point(Panel1.Width + SplitterWidth, 0);
}
// Update the splitter distance and percentage to reflect new positions
_splitterDistance = Panel1.Width;
_splitterPercent = (double)Panel1.Width / (double)Width;
}
else
{
// Find the maximum allowed panel width
int panelMax = Width - SplitterWidth;
// Find actual pixel width of first panel but limited to maximum allowed
int panel1Width = Math.Min(SplitterDistance, panelMax);
// Enfore the minimum panel1 width
panel1Width = Math.Max(Panel1MinSize, panel1Width);
// Size the panels
Panel1.Size = new Size(panel1Width, Height);
Panel2.Size = new Size(Width - panel1Width - SplitterWidth, Height);
// Positioning depends on right-to-left layout setting
if (rtl)
{
Panel1.Location = new Point(Width - panel1Width, 0);
Panel2.Location = Point.Empty;
}
else
{
Panel1.Location = Point.Empty;
Panel2.Location = new Point(panel1Width + SplitterWidth, 0);
}
// Update the percentage but not if this occurs because of a resize operation
if (!_resizing)
_splitterPercent = (double)panel1Width / (double)Width;
}
// Separator rect depends on right-to-left layout setting
if (rtl)
separatorRect = new Rectangle(Panel2.Right, 0, SplitterWidth, Height);
else
separatorRect = new Rectangle(Panel1.Right, 0, SplitterWidth, Height);
}
else
{
// Do we used a fixed size for the first panel?
if (FixedPanel == FixedPanel.Panel1)
{
// Set the fixed size of first panel, and fill remaining space with
// second but applying the second panel minimum size specification
Panel1.Size = new Size(Width, _fixedDistance);
Panel2.Size = new Size(Width, Math.Max((Height - SplitterWidth - _fixedDistance), Panel2MinSize));
Panel1.Location = Point.Empty;
Panel2.Location = new Point(0, Panel1.Height + SplitterWidth);
// Update the splitter distance and percentage to reflect new positions
_splitterDistance = Panel1.Height;
_splitterPercent = (double)Panel1.Height / (double)Height;
}
else if (FixedPanel == FixedPanel.Panel2)
{
// Set the fixed size of second panel, and fill remaining space with
// first but applying the first panel minimum size specification
Panel2.Size = new Size(Width, _fixedDistance);
Panel1.Size = new Size(Width, Math.Max((Height - SplitterWidth - _fixedDistance), Panel1MinSize));
Panel1.Location = Point.Empty;
Panel2.Location = new Point(0, Panel1.Height + SplitterWidth);
// Update the splitter distance and percentage to reflect new positions
_splitterDistance = Panel1.Height;
_splitterPercent = (double)Panel1.Height / (double)Height;
}
else
{
// Find the maximum allowed panel1 height
int panel1Max = Height - SplitterWidth;
// Find actual pixel height of first panel but limited to maximum allowed
int panel1Height = Math.Min(SplitterDistance, panel1Max);
// Enfore the minimum panel1 height
panel1Height = Math.Max(Panel1MinSize, panel1Height);
// Size the panels
Panel1.Size = new Size(Width, panel1Height);
Panel2.Size = new Size(Width, Height - panel1Height - SplitterWidth);
Panel1.Location = Point.Empty;
Panel2.Location = new Point(0, panel1Height + SplitterWidth);
// Update the percentage but not if this occurs because of a resize operation
if (!_resizing)
_splitterPercent = (double)panel1Height / (double)Height;
}
separatorRect = new Rectangle(0, Panel1.Bottom, Width, SplitterWidth);
}
}
else if (Panel1Collapsed)
{
Panel2.Size = Size;
Panel2.Location = Point.Empty;
}
else if (Panel2Collapsed)
{
Panel1.Size = Size;
Panel1.Location = Point.Empty;
}
}
}
// Let base class layout child controls
base.OnLayout(levent);
// Update the separator element manually
if (_drawSeparator != null)
_drawSeparator.ClientRectangle = separatorRect;
}