XPTable.Models.Table.UpdateScrollBars C# (CSharp) Method

UpdateScrollBars() public method

Updates the scrollbars to reflect any changes made to the Table
public UpdateScrollBars ( ) : void
return void
        public void UpdateScrollBars()
        {
            // fix: Add width/height check as otherwise minimize
            //      causes a crash
            //      Portia4ever ([email protected])
            //      13/09/2005
            //      v1.0.1
            if (!this.Scrollable || this.ColumnModel == null || this.Width == 0 || this.Height == 0)
                return;

            bool hscroll = (this.ColumnModel.VisibleColumnsWidth > this.Width - (this.BorderWidth * 2));
            bool vscroll = this.TotalRowAndHeaderHeight > (this.Height - (this.BorderWidth * 2) - (hscroll ? SystemInformation.HorizontalScrollBarHeight : 0));

            if (vscroll)
                hscroll = (this.ColumnModel.VisibleColumnsWidth > this.Width - (this.BorderWidth * 2) - SystemInformation.VerticalScrollBarWidth);

            if (hscroll)
            {
                #region Set up the horizontal scrollbar
                Rectangle hscrollBounds = new Rectangle(this.BorderWidth,
                    this.Height - this.BorderWidth - SystemInformation.HorizontalScrollBarHeight,
                    this.Width - (this.BorderWidth * 2),
                    SystemInformation.HorizontalScrollBarHeight);

                if (vscroll)
                {
                    hscrollBounds.Width -= SystemInformation.VerticalScrollBarWidth;
                }

                this.hScrollBar.Visible = true;
                this.hScrollBar.Bounds = hscrollBounds;
                this.hScrollBar.Minimum = 0;
                this.hScrollBar.Maximum = this.ColumnModel.VisibleColumnsWidth;
                // netus fix by Kosmokrat Hismoom  - added check for property Maximum
                // as otherwise resizing could lead to a crash 12/01/06
                this.hScrollBar.Maximum = (this.hScrollBar.Maximum <= 0) ? 0 : this.hScrollBar.Maximum;
                this.hScrollBar.SmallChange = Column.MinimumWidth;
                // fixed by Kosmokrat Hismoom on 7 jan 2006
                this.hScrollBar.LargeChange = (hscrollBounds.Width <= 0) ? 0 : (hscrollBounds.Width - 1);

                if (this.hScrollBar.Value > this.hScrollBar.Maximum - this.hScrollBar.LargeChange)
                    this.hScrollBar.Value = this.hScrollBar.Maximum - this.hScrollBar.LargeChange;
                #endregion
            }
            else
            {
                this.hScrollBar.Visible = false;
                this.hScrollBar.Value = 0;
            }

            if (vscroll)
            {
                Rectangle vscrollBounds = new Rectangle(this.Width - this.BorderWidth - SystemInformation.VerticalScrollBarWidth,
                    this.BorderWidth,
                    SystemInformation.VerticalScrollBarWidth,
                    this.Height - (this.BorderWidth * 2));

                if (hscroll)
                    vscrollBounds.Height -= SystemInformation.HorizontalScrollBarHeight;

                this.vScrollBar.Visible = true;
                this.vScrollBar.Bounds = vscrollBounds;
                this.vScrollBar.Minimum = 0;
                this.vScrollBar.SmallChange = 1;

                int rowcount = this.RowCount - this.TableModel.Rows.HiddenSubRows;
                rowcount = rowcount < 0 ? 0 : rowcount;
                vScrollBar.Maximum = rowcount;

                int visibleRowCount = this.GetVisibleRowCount(hscroll, true);
                vScrollBar.LargeChange = visibleRowCount < 0 ? 0 : visibleRowCount + 1;
            }
            else
            {
                this.vScrollBar.Visible = false;
                this.vScrollBar.Value = 0;
            }
        }
Table