Einzelnen Beitrag anzeigen

hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#12

Re: TStringGrid, wordwrap, 1zeilig sieht es blöd aus

  Alt 20. Jul 2009, 18:43
Hallo,

LÖSUNG

Delphi-Quellcode:
if RowHeights[R]<=AGrid.DefaultRowHeight then
begin
  DrawRect:= Rect; // das hier war es
Delphi-Quellcode:
procedure DrawSGCell(AGrid: TStringGrid; C, R : integer; Rect : TRect;
          Style : TFontStyles; Wrap : boolean; Just : TAlignment;
          CanEdit : boolean);
  { draws formatted contents in string grid cell at col C, row R;
    Style is a set of fsBold, fsItalic, fsUnderline and fsStrikeOut;
    Wrap invokes word wrap for the cell's text; Just is taLeftJustify,
    taRightJustify or taCenter; if CanEdit false, cell will be given
    the background color of fixed cells; call this routine from
    grid's DrawCell event }

var
  S : String;
  S2 : String;
  DrawRect : TRect;
  iAlign : Integer;
begin
  iAlign:= dt_left;
  case Just of
    taCenter : iAlign:= dt_center;
    taRightJustify : iAlign:= dt_right;
  end;

  with AGrid, Canvas do
  begin
    { erase earlier contents from default drawing }
    if (R >= FixedRows) and (C >= FixedCols) and CanEdit then
    begin
// Brush.Color:= AGrid.Brush.Color;
    end
    else
    begin
      Brush.Color:= FixedColor;
    end;

    FillRect(Rect);
    { get cell contents }
    S:= Cells[C, R];

    if length(S) > 0 then
    begin
(*
  original code, keine Ahnung, was das soll ???
*)

      S2:= S;
(*
      case Just of
        taLeftJustify  : S:= ' ' + S;
        taRightJustify : S:= S + ' ';
      end;
*)


      { set font style }
      Font.Style:= Style;
      { copy of cell rectangle for text sizing }
      DrawRect:= Rect;

      if Wrap then
      begin
       { get size of text rectangle in DrawRect, with word wrap }
        DrawText(Handle, PChar(S2), length(S2), DrawRect,
          dt_calcrect or dt_wordbreak or iAlign);
        if (DrawRect.Bottom - DrawRect.Top) > RowHeights[R] then
        begin
          { cell word-wraps; increase row height }
          RowHeights[R]:= DrawRect.Bottom - DrawRect.Top;
          SetGridHeight(AGrid);
        end;

        if RowHeights[R]<=AGrid.DefaultRowHeight then
        begin
          DrawRect:= Rect;
          DrawText(Handle, PChar(S2), length(S2), DrawRect,
                   dt_singleline
                   or dt_vcenter // klappt nicht, steht auch so im SDK
                   or iAlign);
        end
        else
        begin
          DrawText(Handle, PChar(S2), length(S2), DrawRect,
                   dt_wordbreak
                   or iAlign);
        end;
      end
      else
      begin
        { no word wrap }
        DrawText(Handle, PChar(S2), length(S2), DrawRect,
                 dt_singleline
                 or dt_vcenter
                 or iAlign);
      end; { if Wrap then }
    end; { if length(S) > 0 then }  

   { restore no font styles }
    Font.Style:= [];
  end;
end;

Puh !!!
Heiko
  Mit Zitat antworten Zitat