コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var g = e.Graphics;

            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
            g.DrawRectangle(Pens.MediumVioletRed, 0.5f, 0.5f, this.Width - 1, this.Height - 1);

            int totalAvailableWidth = this.Width;

            int[] columnWidths = ColumnPositioning.CalculateColumnWidths(this.Columns, totalAvailableWidth, 10, out int totalOccupiedWidth, out int totalFillableWidth);
            Debug.Assert(columnWidths.Length == this.Columns.Length);

            const int columnHeight = 20;

            int scrollPosition = this.GetHScrollValue();

            int x = -scrollPosition;

            for (int i = 0; i < this.Columns.Length; ++i)
            {
                // Column out of bounds (right). Don't need to draw any more columns.
                if (x > totalAvailableWidth)
                {
                    break;
                }
                var col         = this.Columns[i];
                var columnWidth = columnWidths[i];
                if (x + columnWidth < 0)
                {
                    // Column out of bounds (left). Go to next column until we find one to draw.
                    x += columnWidth;
                    continue;
                }

                double effectiveFillPercentage = (double)(columnWidth - col.Width) / totalFillableWidth * 100.0;

                Brush fillBrush = Brushes.Gray;
                g.FillRectangle(fillBrush, x, 0, columnWidth, columnHeight);
                int borderWidth = i == this.Columns.Length - 1 ? columnWidth - 1 : columnWidth;
                g.DrawRectangle(Pens.Black, x + 0.5f, 0.5f, borderWidth, columnHeight - 1.0f);
                TextRenderer.DrawText(g, FormattableString.Invariant($"{col.Width}/{col.FillWeight} = {columnWidth} | {effectiveFillPercentage:F1} %"), this.Font, new Point(x, 0), Color.White);
                x += columnWidth;
            }

            var sb = new StringBuilder();

            foreach (var width in columnWidths)
            {
                sb.AppendLine(width.ToString());
            }
            sb.AppendLine($"Total available: {totalAvailableWidth}");
            sb.AppendLine($"Total fillable: {totalFillableWidth}");
            sb.AppendLine($"Total occupied: {totalOccupiedWidth}");
            TextRenderer.DrawText(g, sb.ToString(), this.Font, new Point(0, columnHeight), Color.Black);
        }
コード例 #2
0
 private void Button1_MouseMove(object sender, MouseEventArgs e)
 {
     if (!this.resizeDragInfo.Active)
     {
         return;
     }
     ColumnPositioning.ResizeDrag(this.resizeDragInfo, e.X, 10);
     this.control.RecalculateScrollBar();
     this.control.Invalidate();
 }
コード例 #3
0
        public void RecalculateScrollBar()
        {
            int availableWidth = this.Width;

            ColumnPositioning.CalculateColumnTotals(this.Columns, 10, out int totalOccupiedWidth, out _);
            int overhang    = totalOccupiedWidth - availableWidth;
            int smallChange = this.Width / 20;
            int largeChange = (int)(this.Width / 2.5);

            ScrollBarHelper.SetScrollBarRangeEtc(this.hScrollBar, overhang, smallChange, largeChange);
            this.Invalidate();
        }
コード例 #4
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     if (e.Button != MouseButtons.Left)
     {
         return;
     }
     int[] columnWidths = ColumnPositioning.CalculateColumnWidths(this.Columns, this.Width, 10, out _, out _);
     ColumnPositioning.HitTest(columnWidths, this.GetHScrollValue(), e.X, 5, out int columnIndex, out bool resizeHandle);
     if (resizeHandle)
     {
         this.resizeDragInfo = new ResizeDragInfo(this.Columns[columnIndex], e.X);
     }
 }
コード例 #5
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (this.resizeDragInfo.Active)
     {
         this.Cursor = Cursors.VSplit;
         ColumnPositioning.ResizeDrag(this.resizeDragInfo, e.X, 10);
         this.RecalculateScrollBar();
         return;
     }
     int[] columnWidths = ColumnPositioning.CalculateColumnWidths(this.Columns, this.Width, 10, out _, out _);
     ColumnPositioning.HitTest(columnWidths, this.GetHScrollValue(), e.X, 5, out _, out bool resizeHandle);
     this.Cursor = resizeHandle ? Cursors.VSplit : Cursors.Default;
 }