ARTICLE

While we need a C# filled arc in each DataGridView row

private Rectangle GetCellBounds(int col, int row)
{
    int x = tlp_tra_actual.GetColumnWidths().Take(col).Sum();
    int y = tlp_tra_actual.GetRowHeights().Take(row).Sum();
    int w = tlp_tra_actual.GetColumnWidths()[col];
    int h = tlp_tra_actual.GetRowHeights()[row];
    return new Rectangle(x, y, w, h);
}
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    try
    {
            int row = e.Row;
        var g = e.Graphics;
        float radiusFactor = 1.4f; // 1.0 = original, >1 = bigger arc
    
        Rectangle cellRect = GetCellBounds(0, row);
    
        // Make radius bigger than cell min size * factor
        int baseRadius = Math.Min(cellRect.Width, cellRect.Height);
        int radius = (int)(baseRadius * radiusFactor);
    
        using (GraphicsPath path = new GraphicsPath())
        {
            // Move starting point higher up (because arc is larger)
            path.StartFigure();
            path.AddLine(cellRect.Left, cellRect.Bottom - radius, cellRect.Left, cellRect.Bottom);
            path.AddLine(cellRect.Left, cellRect.Bottom, cellRect.Left + radius, cellRect.Bottom);
    
            // Bigger arc, starts at bottom and sweeps up to left
            path.AddArc(
                cellRect.Left,                    // arc X
                cellRect.Bottom - radius,         // arc Y
                radius,                           // arc width
                radius,                           // arc height
                90, 90);
    
            path.CloseFigure();
    
            using (Brush brush = new SolidBrush(Color.FromArgb(150, Color.DarkBlue)))
            {
                g.FillPath(brush, path);
            }
        }
    }
    catch
    {
    
    }
}

Thanks

NEWSLETTER

Subscribe to the Algolassi newsletter

Get practical .NET, C#, Blazor, SQL Server and developer tips in your inbox. No spam, just useful updates.

🤖 AlgoLassi Assistant Have a question about this tutorial?

Ask AlgoLassi and get an answer plus the tutorials worth studying next.

Ask a question

đŸ’Ŧ Comments

Sign in with Google to publish immediately, or comment anonymously and wait for approval.

Comments will appear here when available.