protected override void RefreshControlPositions()
{
if (this.ManagedControl == null) return;
if (busyRefreshing) return;
try
{
busyRefreshing = true;
ResetCurrentPosToTopLeft();
int rowStart = 0;
int lastVisible = 0;
int currentRowHeight = 0;
int currentLine = 0;
var controlsInRow = new System.Collections.Generic.List<IControlHabanero>();
var controlRows = new List<List<IControlHabanero>>();
for (int controlNumber = 0; controlNumber < this._controls.Count; controlNumber++)
{
IControlHabanero ctl = GetControl(controlNumber);
if (IsControlOnANewLine(controlNumber, currentLine))
{
MoveCurrentPosToStartOfNextRow(currentRowHeight);
currentLine++;
}
if (ctl.Visible)
{
if (ControlDoesNotFitOnCurrentRow(ctl))
{
if (IsGluedToAnotherControl(controlNumber))
{
GetGluedControlToMoveToNewLineIfPossible(ref controlNumber, ref ctl);
}
if (_alignment == Alignments.Centre)
{
ShiftControlsRightForCentering(rowStart, controlNumber - 1);
}
MoveCurrentPosToStartOfNextRow(currentRowHeight);
var thisRow = new List<IControlHabanero>();
foreach (var thisRowCtl in controlsInRow)
thisRow.Add(thisRowCtl);
controlRows.Add(thisRow);
currentRowHeight = InitialiseNewRow(controlNumber, out rowStart, controlsInRow);
}
controlsInRow.Add(ctl);
SetControlPosition(ctl);
_currentPos.X += ctl.Width + HorizontalGapSize;
if (ctl.Height > currentRowHeight)
{
currentRowHeight = ctl.Height;
}
lastVisible = controlNumber;
}
if (_alignment == Alignments.Centre)
{
if ((controlNumber == this._controls.Count - 1) && (lastVisible >= rowStart))
{
ShiftControlsRightForCentering(rowStart, lastVisible);
}
}
}
controlRows.Add(controlsInRow);
if (_alignment == Alignments.Right && rowStart == 0)
{
SetUpTabIndexForAlignmentRight(rowStart, controlsInRow);
}
var totalRowsHeight = this.VerticalGapSize;
foreach (var row in controlRows)
{
var maxHeight = 0;
foreach (var ctl in row)
{
if (ctl.Height > maxHeight)
maxHeight = ctl.Height;
}
foreach (var ctl in row)
{
var padTop = (int)Math.Ceiling(((decimal)maxHeight - (decimal)ctl.Height) / 2);
ctl.Top += padTop;
}
totalRowsHeight += maxHeight + this.VerticalGapSize;
}
//this.ManagedControl.SuspendLayout();
this.ManagedControl.Height = totalRowsHeight;
//this.ManagedControl.ResumeLayout(true);
}
finally
{
busyRefreshing = false;
}
}