Пример #1
0
        private void SetVerticalSplitPosition(int index, float percentage)
        {
            percentage = Math.Min(100, Math.Max(0, percentage));
            if (ColumnCount == 0 || index < 0 || index >= ColumnCount - 1 || Width <= 0)
            {
                return;
            }

            var widths         = ColumnStyles.OfType <ColumnStyle>().Select(x => x.Width).ToList();
            var currentPercent = widths.GetRange(0, index + 1).Sum();

            if (percentage < currentPercent)
            {
                // <--
                var diff = currentPercent - percentage;
                for (var i = index; i >= 0 && diff > 0; i--)
                {
                    var w  = widths[i];
                    var nw = Math.Max(MinimumViewSize, w - diff);
                    widths[i]          = nw;
                    widths[index + 1] += (w - nw);
                    diff -= (w - nw);
                }
            }
            else if (percentage > currentPercent)
            {
                // -->
                var diff = percentage - currentPercent;
                for (var i = index + 1; i < widths.Count && diff > 0; i++)
                {
                    var w  = widths[i];
                    var nw = Math.Max(MinimumViewSize, w - diff);
                    widths[i]      = nw;
                    widths[index] += (w - nw);
                    diff          -= (w - nw);
                }
            }
            for (var i = 0; i < ColumnCount; i++)
            {
                widths[i]             = (float)Math.Round(widths[i] * 10) / 10;
                ColumnStyles[i].Width = widths[i];
            }
        }