开发者

Changing a border color on a Windows Form

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜