Beispiel #1
0
        private void UpdateScrollBars()
        {
            if (!_AutoScroll)
            {
                RemoveHScrollBar();
                RemoveVScrollBar();
                if (_Thumb != null)
                {
                    this.Controls.Remove(_Thumb);
                    _Thumb.Dispose();
                    _Thumb = null;
                }
                return;
            }

            Rectangle innerBounds = ElementStyleLayout.GetInnerRect(this.BackgroundStyle, this.ClientRectangle);
            // Check do we need vertical scrollbar
            Size scrollSize = _AutoScrollMinSize;
            if (scrollSize.Height > innerBounds.Height)
            {
                if (_VScrollBar == null)
                {
                    _VScrollBar = new DevComponents.DotNetBar.VScrollBarAdv();
                    _VScrollBar.Appearance = _ScrollBarAppearance;
                    _VScrollBar.Width = SystemInformation.VerticalScrollBarWidth;
                    this.Controls.Add(_VScrollBar);
                    _VScrollBar.BringToFront();
                    _VScrollBar.Scroll += new ScrollEventHandler(VScrollBarScroll);
                }
                if (_VScrollBar.Minimum != 0)
                    _VScrollBar.Minimum = 0;
                if (_VScrollBar.LargeChange != innerBounds.Height && innerBounds.Height > 0)
                    _VScrollBar.LargeChange = innerBounds.Height;
                _VScrollBar.SmallChange = 22;
                if (_VScrollBar.Maximum != _AutoScrollMinSize.Height)
                    _VScrollBar.Maximum = _AutoScrollMinSize.Height;
                if (_VScrollBar.Value != -_AutoScrollPosition.Y)
                    _VScrollBar.Value = (Math.Min(_VScrollBar.Maximum, Math.Abs(_AutoScrollPosition.Y)));
            }
            else
                RemoveVScrollBar();

            // Check horizontal scrollbar
            if (scrollSize.Width > innerBounds.Width)
            {
                if (_HScrollBar == null)
                {
                    _HScrollBar = new DevComponents.DotNetBar.ScrollBar.HScrollBarAdv();
                    _HScrollBar.Appearance = _ScrollBarAppearance;
                    _HScrollBar.Height = SystemInformation.HorizontalScrollBarHeight;
                    this.Controls.Add(_HScrollBar);
                    _HScrollBar.BringToFront();
                    _HScrollBar.Scroll += new ScrollEventHandler(HScrollBarScroll);
                }
                if (_HScrollBar.Minimum != 0)
                    _HScrollBar.Minimum = 0;
                if (_HScrollBar.LargeChange != innerBounds.Width && innerBounds.Width > 0)
                    _HScrollBar.LargeChange = innerBounds.Width;
                if (_HScrollBar.Maximum != _AutoScrollMinSize.Width)
                    _HScrollBar.Maximum = _AutoScrollMinSize.Width;
                if (_HScrollBar.Value != -_AutoScrollPosition.X)
                    _HScrollBar.Value = (Math.Min(_HScrollBar.Maximum, Math.Abs(_AutoScrollPosition.X)));
                _HScrollBar.SmallChange = 22;
            }
            else
                RemoveHScrollBar();
            RepositionScrollBars();
        }