Einzelnen Beitrag anzeigen

Benutzerbild von SaFu
SaFu

Registriert seit: 8. Nov 2006
1.360 Beiträge
 
Delphi 10.3 Rio
 
#4

Re: StringGrid Zelle bei ButtonKlick färben?

  Alt 22. Mai 2007, 12:12
Guck mal vielleicht hilft dir das ist sowas ähnliches

Delphi-Quellcode:
procedure TForm7.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var Celltext :string;
    Farbe :boolean;
    Textformat :cardinal;
    n :integer;
begin
  Textformat:= DT_SINGLELINE;
   with (Sender as TStringGrid) do

    begin
     Celltext:= Cells[ACol, ARow];
     Farbe:= True; //Standardeinstellung der Zellen ist einfarbig

      if (Cells[ACol,ARow] = 'fa') or (Cells[ACol,ARow] = 'FA')then
        begin
          Canvas.Brush.Color:= ClRed; //Zellenfarbe
          Canvas.Font.Color:= ClWhite; //Schriftfarbe
          Canvas.Font.Style:= Canvas.Font.Style + [fsBold]; //Text fett
        end;

     if (Cells[ACol,ARow] = 'np') or (Cells[ACol,ARow] = 'NP')then
        begin
          Canvas.Brush.Color:= ClBlue; //Zellenfarbe
          Canvas.Font.Color:= ClWhite; //Schriftfarbe
          Canvas.Font.Style:= Canvas.Font.Style + [fsBold]; //Text fett
        end;

     if (Cells[ACol,ARow] = 'aa') or (Cells[ACol,ARow] = 'AA')then
       begin
        Canvas.Brush.Color:= ClGreen; //Zellenfarbe
        Canvas.Font.Color:= ClWhite; //Schriftfarbe
        Canvas.Font.Style:= Canvas.Font.Style + [fsBold]; //Text fett
       end;

    if (Farbe) then
       begin
        SetBkMode(StringGrid1.Canvas.Handle, OPAQUE); //Hintergrund überschreiben
        Canvas.FillRect(Rect)
       end;

    if (ACol = 1) or (ACol = 0) then
       begin
        Textformat:= Textformat or DT_CENTER or DT_VCENTER ; //Text wird zentriert
        Canvas.Font.Style:= Canvas.Font.Style + [fsBold]; //Text fett
       end;

    if (ACol > 1) then //Zentrieren für alle Zellen
       begin
        Textformat:= Textformat or DT_CENTER or DT_VCENTER; //Text wird zentriert
       end;
  //Hier wird nun der Text ausgegeben
  DrawText(Canvas.Handle, PChar(Celltext), Length(celltext), Rect,Textformat);
end;
musst du dir nur noch umbastel für dein button

Gruss sascha
"... Wie gesagt, die Nutzer von 10, 12, 14 Zoll Display's werden deine Seite nicht in voller Pracht sehen können, ...

Surft Ihr mit dem Taschenrechner?"
  Mit Zitat antworten Zitat