rt

解决方案 »

  1.   

    //在OnDrawCell事件中写
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      TopRect, BottomRect: TRect;
    begin
      if (ARow = 1) and (ACol = 2) then  //在第1行第2列中画
      begin
        TopRect := Rect;
        TopRect.Bottom := (TopRect.Top + (Rect.Bottom - Rect.Top) div 4);
        SubtractRect(BottomRect, Rect, TopRect);    with StringGrid1.Canvas do
        begin
          Brush.Color := clGreen;
          FillRect(TopRect);
          Brush.Color := clRed;
          FillRect(BottomRect);
        end;
      end;
    end;
      

  2.   

    //忘了把文本写回去!加上DrawText
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      TopRect, BottomRect: TRect;
    begin
      if (ARow = 1) and (ACol = 2) then  //在第1行第2列中画
      begin
        TopRect := Rect;
        TopRect.Bottom := TopRect.Top + (Rect.Bottom - Rect.Top) div 4;
        SubtractRect(BottomRect, Rect, TopRect);    with StringGrid1.Canvas do
        begin
          Brush.Color := clGreen;
          FillRect(TopRect);
          Brush.Color := clRed;
          FillRect(BottomRect);
          DrawText(Handle, PChar(StringGrid1.Cells[ACol, ARow]),
            Length(StringGrid1.Cells[ACol, ARow]), Rect,
            DT_CENTER or DT_SINGLELINE or DT_VCENTER);
        end;
      end;
    end;