Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi StringGrid Mehrzeilig (https://www.delphipraxis.net/19288-stringgrid-mehrzeilig.html)

Robert_G 31. Mär 2004 17:45

Re: StringGrid Mehrzeilig
 
Ich hätte es so gelöst (im OnDrawCell des Grids) :
Delphi-Quellcode:
Var
  CrLfPos, PrevPos, i                  : Integer;
  SL                                   : TStrings;
Begin
  With Sender As TStringGrid Do
  Begin

    If aCol < FixedCols Then Exit;
    If aRow < FixedRows Then Exit;

    PrevPos := 1;
    CrLfPos := PosEx(#13#10, Cells[aCol, aRow], PrevPos);
    If CrLfPos > 0 Then
    Begin
      SL := TStringList.Create;
      Try
        // such Zeilenumbrüche
        While CrLfPos > 0 Do
        Begin
          // rein in die SL
          SL.Add(Copy(Cells[aCol, aRow], PrevPos, CrLfPos - PrevPos));
          PrevPos := CrLfPos + 2;
          CrLfPos := PosEx(#13#10, Cells[aCol, aRow], PrevPos);
        End;

        If SL.Count > 0 Then
          // Canvas des Grids
          With Canvas Do
          Begin
            SL.Add(Copy(Cells[aCol, aRow], PrevPos, Length(Cells[aCol, aRow])));
            FillRect(Rect);
            For i := 0 To pred(SL.Count) Do
              // Zeichne Text (-Font.Height +2 entspricht einer Zeilenhöhe)
              TextOut(Rect.Left + 2, Rect.Top + 2 + ((-Font.Height + 2) * i), Sl[i]);
          End;

      Finally
        FreeAndNil(SL);
      End;
    End;
  End;
End;
Nachtrag: Ich habe es noch ausgebessert, in der vorherigen Variante wurde immer die SL erzeugt... :oops:

kiar 31. Mär 2004 18:00

Re: StringGrid Mehrzeilig
 
sorry :oops:

hatte vergessen, das ich hier mit Editmask arbeite und im Ondrawcell die textformatierung eingestellt habe.

:wall:

raik


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:47 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz