RT3X

解决方案 »

  1.   

    在DrawCell事件中写:
    if ACol = x then
     DrawText(SG.Canvas.Handle,PChar(SG.Cells[ACol,ARow]),Length(SG.Cells[ACol,ARow]),Rect,DT_Right);
      

  2.   

    procedure TFrmReturns.SgSaleDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      sg: TStringGrid;   //中间变量
      CellText: String;  //单元格的字符
      aTextLeft, aTextTop: Integer;     //字符串的左边距和上边距
      aTextWidth, aTextHeight: Integer; //字符串的宽和高
    begin
      inherited;
      sg := (Sender as TStringGrid);
      CellText := sg.Cells[ACol, ARow];
      sg.Canvas.Font := sg.Font;
      if (gdFixed in State) then  // String Grid Cell 为固定
      begin
        sg.Canvas.Brush.Color := sg.FixedColor;
        sg.Canvas.FillRect(Rect);
        Frame3D(sg.Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
      end
      else
      begin
        // String Grid Cell 目前被选取 或 输入焦点
        if (gdSelected in State) or (gdFocused in State) then
        begin
          sg.Canvas.Brush.Color := clHighlight;
          sg.Canvas.Font.Color := clHighlightText;
        end
        else  // String Grid Cell 般状况
        begin
          sg.Canvas.Brush.Color := sg.Color;
          sg.Canvas.Font.Color := sg.Font.Color;
        end;
        sg.Canvas.FillRect(Rect);
      end;
      aTextWidth := sg.Canvas.TextWidth(CellText);
      aTextHeight := sg.Canvas.TextHeight(CellText);
      aTextTop := Rect.Top + (Rect.Bottom - Rect.Top - aTextHeight) div 2;     // 文字垂直置中
      case ARow of
      0:begin
          aTextLeft := Rect.Left + (Rect.Right - Rect.Left - aTextWidth) div 2;
        end;
      else
        case ACol of
        1..2, 9: aTextLeft := Rect.Left + 2;                                        // 文字置左
        3..6: aTextLeft := Rect.Right - aTextWidth - 2;                             // 文字靠右
        7..8: aTextLeft := Rect.Left + (Rect.Right - Rect.Left - aTextWidth) div 2; // 文字置中
        else
          aTextLeft := Rect.Left + 2;
        end;
      end;
      sg.Canvas.TextRect(Rect, aTextLeft, aTextTop, CellText) ;
    end;
      

  3.   

    procedure TfmgFundsDetail.RzGrdDataDrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
    var
      Area: TRect;
    begin
      with RzGrdData, RzGrdData.Canvas do begin       //贷币右对齐
        FillRect(Rect);
        Area:= Rect;
        InflateRect(Area, -2, -2);
        if (ACol=3)or  (ACol=4) or (ACol=5) then DrawText(Handle, PChar(Cells[ACol, ARow]),
          Length(Cells[ACol, ARow]), Area, DT_RIGHT)
        else TextRect(Rect, Rect.Left + 4, Rect.Top + 2, Cells[ACol, ARow]);
      end;
    end;