Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi StringGrid: Aussehen ändern (https://www.delphipraxis.net/22333-stringgrid-aussehen-aendern.html)

Tubos 16. Mai 2004 08:16


StringGrid: Aussehen ändern
 
Hallo;

kann man in einem Stringgrid
a) die Schrift in den Zellen zentrieren?
b) Eine Hintergrundfarbe für einzelne Zeilen / Spalten oder Zellen festlegen?
Wenn ja, wie?

toms 16. Mai 2004 08:19

Re: StringGrid: Aussehen ändern
 
Hi,

Zitat:

a) die Schrift in den Zellen zentrieren?
Bei Google suchenstringgrid zentrieren delphi

Zitat:

b) Eine Hintergrundfarbe für einzelne Zeilen / Spalten oder Zellen festlegen?
Bei Google suchenstringgrid farben delphi

Tubos 16. Mai 2004 08:33

Re: StringGrid: Aussehen ändern
 
Danke!

Tubos 16. Mai 2004 09:53

Re: StringGrid: Aussehen ändern
 
Der Code zum Text ausrichten funktioniert bei mir nicht:

Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);

  procedure WriteText(StringGrid: TStringGrid; ACanvas: TCanvas; const ARect: TRect;
    const Text: string; Format: Word);
  const
    DX = 2;
    DY = 2;
  var
    S: array[0..255] of Char;
    B, R: TRect;
  begin
    with Stringgrid, ACanvas, ARect do
    begin
      case Format of
        DT_LEFT: ExtTextOut(Handle, Left + DX, Top + DY,
            ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text), Length(Text), nil);

        DT_RIGHT: ExtTextOut(Handle, Right - TextWidth(Text) - 3, Top + DY,
            ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text),
            Length(Text), nil);

        DT_CENTER: ExtTextOut(Handle, Left + (Right - Left - TextWidth(Text)) div 2,
            Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect,
            StrPCopy(S, Text), Length(Text), nil);
      end;
    end;
  end;

  procedure Display(StringGrid: TStringGrid; const S: string; Alignment: TAlignment);
  const
    Formats: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  begin
    WriteText(StringGrid, StringGrid.Canvas, Rect, S, Formats[Alignment]);
  end;
begin
  // Right-justify columns 0-2 
  // Spalten 0-2 rechts ausrichten.
  if ACol in [0..2] then
    Display(StringGrid1, StringGrid1.Cells[ACol, ARow], taRightJustify)

    // Center the first row
    // Erste zeile zentrieren
    if ARow = 0 then
      Display(StringGrid1, StringGrid1.Cells[ACol, ARow], taCenter)
  end;
Es sind weiterhin alle Zellen links ausgerichtet.

kiar 16. Mai 2004 10:45

Re: StringGrid: Aussehen ändern
 
das sollte funktionieren:
Delphi-Quellcode:
 
with grid do
 begin
   Rect:= Cellrect(ACol, ARow);
   Canvas.Brush.color:=clred;
   Canvas.FillRect(Rect);
   DrawText(Canvas.Handle, PChar(sText),
            length(sText), Rect, DT_Singleline or DT_Center or DT_VCenter);
end;

das ganze im drawcell des grid's
raik


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:25 Uhr.

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