简体   繁体   English

更改Windows窗体上的边框颜色

[英]Changing a border color on a Windows Form

有人知道如何在Windows窗体中更改datagridview的边框颜色吗?

You can't, it is drawn with the color that the user selected in her preferred theme, selected in Control Panel's Display applet. 您不能使用在控制面板的“显示”小程序中选择的用户在首选主题中选择的颜色绘制。 Overriding the user preference is risky, but you can do so by drawing it yourself. 覆盖用户偏好是有风险的,但您可以通过自己绘制它来实现。 Set the DGV's BorderStyle property to None and draw a border yourself in the form's OnPaintBackground() method. 将DGV的BorderStyle属性设置为None,并在表单的OnPaintBackground()方法中自己绘制边框。 For example: 例如:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM