请问datagridview的网格线的问题

xiaozi141 2009-08-17 08:35:00
我想修改列的网格线的颜色,就是竖着的线的颜色,而且想设置每列之间的线的颜色不一致,我式了一下gridcolor貌似不行..麻烦哪位大虾指导下我,谢谢~
...全文
392 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsj_zrp 2009-08-18
  • 打赏
  • 举报
回复
只能自己画了,datagridview绘制的时候,是按单元格来绘制的矩形,按你的要求就是绘制矩形的左右边框颜色不同了
给你一段代码是绘制行头和列头的

protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
Color mLinearColor1 = Color.FromArgb(248, 250, 251);
Color mLinearColor2 = Color.FromArgb(196, 207, 224);
Color mGridColor = Color.FromArgb(120, 147, 191); //网格线的颜色
Color mHasFocusedColor = Color.DarkCyan; //控件的焦点框颜色


Rectangle Rect = new Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1);
LinearGradientBrush LinearGradientBrushs = new LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, LinearGradientMode.Vertical);



try
{
if (e.RowIndex == -1 || e.ColumnIndex == -1)
{
e.Graphics.FillRectangle(LinearGradientBrushs, Rect);
e.Graphics.DrawRectangle(new Pen(mGridColor), Rect);
e.PaintContent(e.CellBounds);
e.Handled = true;
}
}

catch
{ }
finally
{
if (LinearGradientBrushs != null)
{
LinearGradientBrushs.Dispose();
}

}

/*不显示焦点颜色*/
this.DefaultCellStyle.SelectionBackColor = Color.Transparent ;
this.DefaultCellStyle.SelectionForeColor = Color.Black ;


base.OnCellPainting(e);
}
qqiuzaihui 2009-08-18
  • 打赏
  • 举报
回复
// Change the Border and Gridline Styles in the Windows Forms DataGridView ControlSamples:

this.dataGridView1.GridColor = Color.BlueViolet;  
this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
this.dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
this.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;


liffe 2009-08-18
  • 打赏
  • 举报
回复
好像得自己绘制。。。。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧