// custom drawing for cells with custom borders private void _flex_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e) { // we only want cells with style set to "Border" CellStyle s = _flex.GetCellStyle(e.Row, e.Col); if (s == null || s.Name != "Border") { return; } // draw cell content as usual e.DrawCell(); // get custom border widths for this cell // (depends on neighbor cells) Margins m = GetBorderMargins(e.Row, e.Col); // draw custom borders Rectangle rc; Graphics g = e.Graphics; if (m.Top > 0) { rc = e.Bounds; rc.Height = m.Top; g.FillRectangle(_bdrBrush, rc); } if (m.Left > 0) { rc = e.Bounds; rc.Width = m.Left; g.FillRectangle(_bdrBrush, rc); } if (m.Bottom > 0) { rc = e.Bounds; rc.Y = rc.Bottom - m.Bottom; rc.Height = m.Bottom; g.FillRectangle(_bdrBrush, rc); } if (m.Right > 0) { rc = e.Bounds; rc.X = rc.Right - m.Right; rc.Width = m.Right; g.FillRectangle(_bdrBrush, rc); } }