/* VB
             Private Sub dgvLegends_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgvLegends.CellPainting
        'Draw custom cell borders.
        'If current column is DisplayName...
        If dgvLegends.Columns("DisplayName").Index = e.ColumnIndex AndAlso e.RowIndex >= 0 Then
                Dim Brush As New SolidBrush(dgvLegends.ColumnHeadersDefaultCellStyle.BackColor)
                e.Graphics.FillRectangle(Brush, e.CellBounds)
                Brush.Dispose()
                e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentBackground)

                ControlPaint.DrawBorder(e.Graphics, e.CellBounds, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid)

            e.Handled = True
        End If
    End Sub
             */
            if (e.RowIndex == 0 || e.ColumnIndex == 0)
            {
                Brush b = new SolidBrush(Color.Black);
                e.Graphics.FillRectangle(b, e.CellBounds);
                b.Dispose();
                e.Paint(e.CellBounds, DataGridViewPaintParts.All | DataGridViewPaintParts.ContentBackground);
                ControlPaint.DrawBorder(e.Graphics, e.CellBounds, Color.Black, 0, ButtonBorderStyle.Outset,
                    Color.Black, 0, ButtonBorderStyle.Outset, Color.Black, 1,
                    ButtonBorderStyle.Outset, Color.Black, 1, ButtonBorderStyle.Outset);
                e.Handled = true;
            }

e.Paint의 매개변수를 잘살펴봐서 적용 시켜야 한다.

 

한개의 Cell의 Border를 변경하는게 아니라서

Border가 겹쳐서 이상하게 보이는 문제 해결한 코드이다.

 

위의 코드에서는

left와 top의 선의 크기를 0으로 주어서

Border를 겹치지 않게 그리고 있다.

+ Recent posts