有谁知道如何更改窗体中的datagridview的边框颜色?
您不能,它是用用户在首选主题中选择的颜色绘制的,在“控制面板”的“显示”小程序中选择。 覆盖用户的偏好是有风险的,但是你可以自己画一下。 将DGV的BorderStyle属性设置为None,并在窗体的OnPaintBackground()方法中自己绘制边框。 例如:
protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); Rectangle rc = new Rectangle(dataGridView1.Left - 1, dataGridView1.Top - 1, dataGridView1.Size.Width + 1, dataGridView1.Size.Height + 1); e.Graphics.DrawRectangle(Pens.Fuchsia, rc); }