Beispiel #1
0
        private void RecalcScrollBars()
        {
            Rectangle vsize = _control.VirtualSize;
            float     zoom  = _control.Zoom;

            //int hLargeChange = _control.GetScrollLargeChange(ScrollOrientation.HorizontalScroll);
            //int vLargeChange = _control.GetScrollLargeChange(ScrollOrientation.VerticalScroll);

            //int hSmallChange = _control.GetScrollSmallChange(ScrollOrientation.HorizontalScroll);
            //int vSmallChange = _control.GetScrollSmallChange(ScrollOrientation.VerticalScroll);

            bool hEnabled = _control.GetScrollEnabled(ScrollOrientation.HorizontalScroll);
            bool vEnabled = _control.GetScrollEnabled(ScrollOrientation.VerticalScroll);

            int width  = _control.Control.Width;
            int height = _control.Control.Height;

            if (AutoShowScrollbars)
            {
                int vwidth  = (int)(vsize.Width * zoom);
                int vheight = (int)(vsize.Height * zoom);

                int hSpan = tableLayoutPanel1.GetColumnSpan(panel1);
                int vSpan = tableLayoutPanel1.GetRowSpan(panel1);

                int minWidth  = (hSpan == 1) ? _control.Control.Width : _control.Control.Width - _vScrollBar.Width;
                int minHeight = (vSpan == 1) ? _control.Control.Height : _control.Control.Height - _hScrollBar.Height;
                int maxWidth  = minWidth + _vScrollBar.Width;
                int maxHeight = minHeight + _hScrollBar.Height;

                if (maxWidth >= vwidth && maxHeight >= vheight)
                {
                    ShowHScrollBar(false);
                    ShowVScrollBar(false);
                    width  = maxWidth;
                    height = maxHeight;
                }
                else if (maxWidth >= vwidth)
                {
                    ShowVScrollBar(true);
                    width = minWidth;
                    if (minWidth >= vwidth || _control.WidthSynced)
                    {
                        ShowHScrollBar(false);
                        height = maxHeight;
                    }
                    else
                    {
                        ShowHScrollBar(true);
                        height = minHeight;
                    }
                }
                else if (maxHeight >= vheight)
                {
                    ShowHScrollBar(true);
                    height = minHeight;
                    if (minHeight >= vheight || _control.HeightSynced)
                    {
                        ShowVScrollBar(false);
                        width = maxWidth;
                    }
                    else
                    {
                        ShowVScrollBar(true);
                        width = minWidth;
                    }
                }
                else
                {
                    ShowHScrollBar(true);
                    ShowVScrollBar(true);
                    width  = minWidth;
                    height = minHeight;
                }
            }

            // Update scrollbar properties

            int hSmallChange = width / 10;
            int vSmallChange = height / 10;
            int hLargeChange = (int)(width / 1.5);
            int vLargeChange = (int)(height / 1.5);

            _hScrollBar.Minimum = 0;
            _vScrollBar.Minimum = 0;
            _hScrollBar.Maximum = (width > vsize.Width * zoom) ? 0
                : (int)(((vsize.Width + hLargeChange) * zoom - width) / zoom);
            _vScrollBar.Maximum = (height > vsize.Height * zoom) ? 0
                : (int)(((vsize.Height + vLargeChange) * zoom - height) / zoom);;

            _hScrollBar.SmallChange = hSmallChange;
            _vScrollBar.SmallChange = vSmallChange;
            _hScrollBar.LargeChange = hLargeChange;
            _vScrollBar.LargeChange = vLargeChange;

            _hScrollBar.Value = Math.Min(_hScrollBar.Value, Math.Max(0, _hScrollBar.Maximum - _hScrollBar.LargeChange));
            _vScrollBar.Value = Math.Min(_vScrollBar.Value, Math.Max(0, _vScrollBar.Maximum - _vScrollBar.LargeChange));

            if (_hScrollBar.Maximum <= 0)
            {
                _hScrollBar.Maximum = 0;
                _hScrollBar.Value   = 0;
                _hScrollBar.Enabled = false;
            }
            else
            {
                _hScrollBar.Enabled = true & hEnabled;
            }

            if (_vScrollBar.Maximum <= 0)
            {
                _vScrollBar.Maximum = 0;
                _vScrollBar.Value   = 0;
                _vScrollBar.Enabled = false;
            }
            else
            {
                _vScrollBar.Enabled = true & vEnabled;
            }

            if (_hScrollBar.Value != _control.GetScrollValue(ScrollOrientation.HorizontalScroll))
            {
                _control.SetScrollValue(ScrollOrientation.HorizontalScroll, _hScrollBar.Value);
            }
            if (_vScrollBar.Value != _control.GetScrollValue(ScrollOrientation.VerticalScroll))
            {
                _control.SetScrollValue(ScrollOrientation.VerticalScroll, _vScrollBar.Value);
            }
        }