/// <summary>
        /// Updates the layout and appearance of the managed controls
        /// </summary>
        protected override void RefreshControlPositions()
        {
            ResetCurrentPosToTopLeft();
            int   rowStart         = 0;
            int   lastVisible      = 0;
            int   currentRowHeight = 0;
            int   currentLine      = 0;
            IList controlsInRow    = new ArrayList();

            for (int i = 0; i < this._controls.Count; i++)
            {
                IChilliControl ctl = GetControl(i);
                if (currentLine < _newLinePositions.Count && (int)_newLinePositions[currentLine] == i)
                {
                    MoveCurrentPosToStartOfNextRow(currentRowHeight);
                    currentLine++;
                }
                if (ctl.Visible)
                {
                    if (ControlDoesNotFitOnCurrentRow(ctl))
                    {
                        if (IsGluedToAnotherControl(i))
                        {
                            if (PreviousControlVisible(i) && BothControlsFitOnALine(i))
                            {
                                //Get the previous control as this is the one that this control is glued to
                                //E.g. a label and this needs to get moved to the new line.
                                i--;
                                ctl = GetControl(i);
                            }
                        }
                        if (_alignment == Alignments.Centre)
                        {
                            ShiftControlsRightForCentering(rowStart, i - 1);
                        }
                        MoveCurrentPosToStartOfNextRow(currentRowHeight);
                        currentRowHeight = InitialiseNewRow(i, out rowStart, controlsInRow);
                    }
                    controlsInRow.Add(ctl);
                    CalculateControlPosition(ctl);
                    _currentPos.X += ctl.Width + GapSize;
                    if (ctl.Height > currentRowHeight)
                    {
                        currentRowHeight = ctl.Height;
                    }
                    lastVisible = i;
                }
                if (_alignment == Alignments.Centre)
                {
                    if ((i == this._controls.Count - 1) && (lastVisible >= rowStart))
                    {
                        ShiftControlsRightForCentering(rowStart, lastVisible);
                    }
                }
            }
            if (_alignment == Alignments.Right && rowStart == 0)
            {
                SetUpTabIndexForAlignmentRight(rowStart, controlsInRow);
            }
        }
 /// <summary>
 /// Adds a control to the layout
 /// </summary>
 /// <param name="ctl">The control to add</param>
 /// <returns>Returns the control once it has been added</returns>
 public override IChilliControl AddControl(IChilliControl ctl)
 {
     _controls.Add(ctl);
     RefreshControlPositions();
     ctl.VisibleChanged += ControlVisibleChangedHandler;
     ctl.Resize += ControlResizedHandler;
     this.ManagedControl.Controls.Add(ctl);
     return ctl;
 }
 /// <summary>
 /// Adds a control to the layout
 /// </summary>
 /// <param name="ctl">The control to add</param>
 /// <returns>Returns the control once it has been added</returns>
 public override IChilliControl AddControl(IChilliControl ctl)
 {
     _controls.Add(ctl);
     RefreshControlPositions();
     ctl.VisibleChanged += ControlVisibleChangedHandler;
     ctl.Resize         += ControlResizedHandler;
     this.ManagedControl.Controls.Add(ctl);
     return(ctl);
 }
 private static void SetUpTabIndexForAlignmentRight(int rowStart, IList controlsInRow)
 {
     for (int ctlCount = 0; ctlCount < controlsInRow.Count; ctlCount++)
     {
         IChilliControl controlInRow = (IChilliControl)controlsInRow[controlsInRow.Count - 1 - ctlCount];
         {
             controlInRow.TabIndex = rowStart + ctlCount;
         }
     }
 }
 /// <summary>
 /// Calculates the control's position in the user interface
 /// </summary>
 /// <param name="ctl">The control in question</param>
 private void CalculateControlPosition(IChilliControl ctl)
 {
     if (_alignment == Alignments.Right)
     {
         ctl.Left = ManagedControl.Width - _currentPos.X - ctl.Width;
     }
     else
     {
         ctl.Left = _currentPos.X;
     }
     ctl.Top = _currentPos.Y;
 }
 /// <summary>
 /// Constructor to initialise a new manager
 /// </summary>
 /// <param name="managedControl">The control to manage e.g. a Panel</param>
 public FlowLayoutManager(IChilliControl managedControl) : base(managedControl)
 {
     _controls = new List<IChilliControl>();
     _newLinePositions = new ArrayList(3);
     _gluePositions = new ArrayList(5);
 }
 /// <summary>
 /// Informs if the specified control fails to fit on the current row
 /// of controls
 /// </summary>
 /// <param name="ctl">The control in question</param>
 /// <returns>Returns true if the item doesn't fit, false if it 
 /// does</returns>
 private bool ControlDoesNotFitOnCurrentRow(IChilliControl ctl)
 {
     return (_currentPos.X + ctl.Width >= ManagedControl.Width - BorderSize);
 }
 /// <summary>
 /// Calculates the control's position in the user interface
 /// </summary>
 /// <param name="ctl">The control in question</param>
 private void CalculateControlPosition(IChilliControl ctl)
 {
     if (_alignment == Alignments.Right)
     {
         ctl.Left = ManagedControl.Width - _currentPos.X - ctl.Width;
     }
     else
     {
         ctl.Left = _currentPos.X;
     }
     ctl.Top = _currentPos.Y;
 }
 /// <summary>
 /// Constructor to initialise a new manager
 /// </summary>
 /// <param name="managedControl">The control to manage e.g. a Panel</param>
 public FlowLayoutManager(IChilliControl managedControl) : base(managedControl)
 {
     _controls         = new List <IChilliControl>();
     _newLinePositions = new ArrayList(3);
     _gluePositions    = new ArrayList(5);
 }
 /// <summary>
 /// Informs if the specified control fails to fit on the current row
 /// of controls
 /// </summary>
 /// <param name="ctl">The control in question</param>
 /// <returns>Returns true if the item doesn't fit, false if it
 /// does</returns>
 private bool ControlDoesNotFitOnCurrentRow(IChilliControl ctl)
 {
     return(_currentPos.X + ctl.Width >= ManagedControl.Width - BorderSize);
 }