日期:2014-05-17 浏览次数:21268 次
//列头背景 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { Color mLinearColor1 = Color.FromArgb(255, 255, 0); //列头颜色 Color mLinearColor2 = Color.FromArgb(255, 255, 255);//列头颜色 Color mGridColor = Color.FromArgb(120, 147, 191); //网格线的颜色 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(); } } //base.OnPaint(e); }
------解决方案--------------------
mouse_leave mouse_enter 之类的事件来改变颜色就可以了