简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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