【问题标题】:Changing all cell border widths in DataGridViews更改 DataGridViews 中的所有单元格边框宽度
【发布时间】:2014-04-21 22:07:38
【问题描述】:

我有一个数据网格视图,我想让所有的单元格边框变粗。有没有可以做到这一点的属性?

【问题讨论】:

    标签: c# visual-studio-2010 datagridview


    【解决方案1】:

    您需要通过向CellPainting 事件处理程序添加代码来进行一些自定义绘制。要将单元格边框设置为无,请使用 CellBorderStyle:

        dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
    
    // CellPainting event handler for your dataGridView1
    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
        if (e.RowIndex == -1 && e.ColumnIndex > -1)
        {
           e.Handled = true;
           using (Brush b = new SolidBrush(dataGridView1.DefaultCellStyle.BackColor))
           {
             e.Graphics.FillRectangle(b, e.CellBounds);
           }
           using (Pen p = new Pen(Brushes.Black))
           {
             p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
             e.Graphics.DrawLine(p, new Point(0, e.CellBounds.Bottom-1), new Point(e.CellBounds.Right, e.CellBounds.Bottom-1));
           }
           e.PaintContent(e.ClipBounds);
        }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    相关资源
    最近更新 更多