首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform,把鼠标放在gridview的表头单元格下如何变背景颜色

2012-10-20 
winform,把鼠标放在gridview的表头单元格上怎么变背景颜色winform,把鼠标移到gridview的表头单元格上怎么

winform,把鼠标放在gridview的表头单元格上怎么变背景颜色
winform,把鼠标移到gridview的表头单元格上怎么变背景颜色

[解决办法]
这个得重绘
[解决办法]
this.datagridview1.ColumnHeadersDefaultCellStyle.BackColor = Color.Red;
好像是这样的
你看下,是不是可以设置到,
[解决办法]
给你一个重绘单元格的例子 鼠标划上去时修改自己拓展

C# code
 //列头背景        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 之类的事件来改变颜色就可以了

热点排行