StringGride 中,
我想给指定的例加颜色,应该怎么做啊,
比如说,第三例.为绿色.

解决方案 »

  1.   

    在cell的自画里实现
    好像onDraw事件
      

  2.   

    在Tstringgrid的OnDraw还是SelfDraw还是DrawCell事件里,如果是第三列,则用自己的绿色去fillrect
      

  3.   

    在ondrawcell事件中可以自画列的背景色,但是存在一个问题,就是列中显示的内容,也需要自画,就是用canvas.textrect另外,还有一个致命的缺点,就是用鼠标点击自画背景色的列后,其中显示内容可能就隐藏看不到了
      

  4.   

    你试验一下这个:
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);  //将第三列背景变为美元绿。
    begin
      if not((acol=2) //这里决定列序号 
         and (arow>=stringgrid1.fixedrows)) then
        exit;  with stringgrid1 do
      begin
         canvas.Brush.color:=clmoneygreen;//这里决定颜色
         canvas.FillRect(Rect);
         canvas.TextOut(rect.left+2,rect.top+2,cells[acol,arow])
      end;
    end;
    我曾经设想把列序号赋一个变量,然后由弹出菜单来传递它,增强互动功能。楼主是否可以一试?若实验成功,说一下,让大家共享。
      

  5.   

    procedure TFrmBaseDept.StrGridDrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
    begin
      //SetGridColor(ARow,ACol,clWhite,$00E1FFFF,Rect,StrGrid);
      with StrGrid do
      begin
        if ACol = 2 then
        begin
          Canvas.Font.Color := clred; //字体颜色为红的
          Canvas.Brush.color:=clMoneyGreen; //背景为 美元绿色
          Canvas.FillRect(Rect);
          Canvas.TextOut(Rect.Left+2,Rect.Top+2,StrGrid.Cells[ACol,ARow]);
        end;
      end;
    end;