日期:2014-05-17  浏览次数:21268 次

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 之类的事件来改变颜色就可以了