stringgrid 字的颜色设置的问题
每格怎么设置字的颜色?
每格的背景色怎么获取?本人想实现的是:在编辑时把字的颜色设成看的见的,非编辑装态时,字的颜色与背景色相同,即看不见.求教!

解决方案 »

  1.   

    取背景色你这样看看var
     red,green,blue:byte;
    begin
      Red:=Byte(StringGrid1.Canvas.Brush.Color);
      Green:=Byte(rgb shr 8);
      Blue:=Byte(rgb shr 16);
    end;
      

  2.   

    任意格的字体可以这样
    比如:
    procedure TForm1.FormShow(Sender: TObject);
    begin
      StringGrid1.Cells[0,0]:='我';
      StringGrid1.Cells[1,0]:='爱';
      StringGrid1.Cells[2,0]:='中';
      StringGrid1.Cells[3,0]:='国';
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      sText: String;
    begin
      sText:=StringGrid1.Cells[ACol,ARow];
      StringGrid1.Canvas.Font.Name:='宋体';
      StringGrid1.Canvas.Font.Size:=11;
      if ACol=0 then
        StringGrid1.Canvas.Font.Color:=clRed;
      if ACol=1 then
        StringGrid1.Canvas.Font.Color:=clBlue;
      if ACol=2 then
        StringGrid1.Canvas.Font.Color:=clYellow;
      StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,sText);end;
    自己用代码控制需要改变颜色的地方
      

  3.   

    OnDrawCell事件。ACol是当前列,ARow是当前行。
      StringGrid1.Canvas.Brush.Color:= clwhite;
      StringGrid1.Canvas.FillRect(Rect);
      if (StringGrid1.Col = ACol) and (StringGrid1.Row = ARow) then
        StringGrid1.Canvas.Font.Color:= clblack
      else
        StringGrid1.Canvas.Font.Color:= clblue;
      StringGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Right + 2, StringGrid1.Cells[ACol, ARow]);
      

  4.   

    老兄,问题是StringGrid1.Cells[ACol, ARow])画了两遍.
      

  5.   

    我的程序有一列是画上去的,我想屏蔽原来的StringGrid1.Cells[ACol, ARow],我是自己把StringGrid1.Cells[ACol, ARow]文字画上去,但现在显示了两遍.