Einzelnen Beitrag anzeigen

Stecky2000

Registriert seit: 7. Mai 2008
Ort: Trebur
66 Beiträge
 
Delphi 2010 Professional
 
#6

Re: Farbe von mit OnDrawcell gefärbter StringGridZelle abfra

  Alt 5. Nov 2008, 13:50
Hallo TaakTaak,

Danke für die Antwort, aber ich verstehe es nicht.

In meinen OnDrawCell wird wie folgt vorgegeangen:

Delphi-Quellcode:

procedure TDPLForm.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);

begin
  with (Sender as TStringGrid) do
  begin
    // Don't change color for first Column, first row
    if (ACol = 0) or (ARow = 0) then
      Canvas.Brush.Color := clBtnFace
    else
    begin
         if (cells[ACol, ARow] <> '') and (cells[ACol, ARow] <> ' ') then
           if cells[ACol, ARow] = StringGrid3.Cells[0, StrToInt(cells[ACol, ARow])] then
               begin
                    if (StringGrid3.Cells[1, StrToInt(cells[ACol, ARow])] = 'x') or (StringGrid3.Cells[1, StrToInt(cells[ACol, ARow])] = 'X') then
                       begin
                            Canvas.Brush.Color := clLime;
                            Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
                            Canvas.FrameRect(Rect);
                       end;
                    if (StringGrid3.Cells[1, StrToInt(cells[ACol, ARow])] = 'd') or (StringGrid3.Cells[1, StrToInt(cells[ACol, ARow])] = 'D') then
                       begin
                            Canvas.Brush.Color := clRed;
                            Canvas.Font.Color := clWhite;
                            Canvas.Font.Style := [fsbold];
                            Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
                            Canvas.FrameRect(Rect);
                       end;
                    if (StringGrid3.Cells[1, StrToInt(cells[ACol, ARow])] = 'g') or (StringGrid3.Cells[1, StrToInt(cells[ACol, ARow])] = 'G') then
                       begin
                            Canvas.Brush.Color := clBlue;
                            Canvas.Font.Color := clWhite;
                            Canvas.Font.Style := [fsbold];
                            Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
                            Canvas.FrameRect(Rect);
                       end;
                    if (StringGrid3.Cells[2, StrToInt(cells[ACol, ARow])] = '') then
                       begin
                            Canvas.Brush.Color := clBlack;
                            Canvas.Font.Color := clWhite;
                            Canvas.Font.Style := [fsbold];
                            Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
                            Canvas.FrameRect(Rect);
                       end;
               end;
    end;
  end;
end;

Ich schreibe die Farbe also nur mit

Canvas.Brush.Color := clLime; rein.

Ich habe darauf hin und nach deiner Antwort folgendes versucht, aber ohne Erfolg:

Color := Integer(StringGrid1.Objects[j, i]); Das geht aber auch nicht, da steht in der Variablen Color immer nur 0 drin;
  Mit Zitat antworten Zitat