开发者

Changing a border color on a Windows Form

开发者 https://www.devze.com 2022-12-18 12:45 出处:网络
Does anybody know how to change the border color of a datagridview开发者_运维技巧 in a windows form?You can\'t, it is drawn with the color that the user selected in her preferred theme, selected in Co

Does anybody know how to change the border color of a datagridview开发者_运维技巧 in a windows form?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号