是否可以修改datagrid scrollbar 的颜色
我已经继承了datagrid,在onPaint事件中添加了
if (this.HorizScrollBar.Visible == true)
{
// Graphics g = e.Graphics;
Graphics g = Graphics.FromHwnd(this.HorizScrollBar.Handle); Brush br = new SolidBrush(Color.Red);
g.FillRectangle(br, this.HorizScrollBar.Location.X, this.HorizScrollBar.Location.Y, this.HorizScrollBar.Size.Width,this.HorizScrollBar.Size.Height);
}
if (this.VertScrollBar.Visible == true)
{
// Graphics g = e.Graphics;
Graphics g = Graphics.FromHwnd(this.VertScrollBar.Handle);
Brush br = new SolidBrush(Color.Red);
g.FillRectangle(br, this.VertScrollBar.Location.X, this.VertScrollBar.Location.Y, this.VertScrollBar.Size.Width,this.VertScrollBar.Size.Height);
}但是没有起作用。

解决方案 »

  1.   

    那估计真的不能修改   代码应该没有问题不过如果你需要完成这个功能,不一定就非要用this.HorizScrollBar.Handle    
    只要获取到了位置,就算是画到Form上也行如果是Control开发   可以直接用datagrid吧   也就是在scrollbar上套层颜色就完了记得之前一个小程序要在Form的Head上画东西的时候  我就画到Windows Desktop上完成的
      

  2.   

    Graphics g = Graphics.FromHwnd(this.HorizScrollBar.Handle); 
    改成其他的
      

  3.   

    每次VertScrollBar 的状态改变了,你应该调用一下刷新函数
    如:  this.Invalidate();
      

  4.   


    怎么套颜色呢?to: wocow2316 
    每次VertScrollBar 的状态改变了,你应该调用一下刷新函数 
    如:  this.Invalidate();先不说调用问题,首要的是颜色根本就没有被改变
      

  5.   

    就是说 使用datagrid 的父容器的Graphics画  或者干脆使用Form的Graphics画