Einzelnen Beitrag anzeigen

Benutzerbild von Helmi
Helmi

Registriert seit: 29. Dez 2003
Ort: Erding, Republik Bayern
3.312 Beiträge
 
Delphi XE2 Professional
 
#8

Re: StringGrid: eine Zeile markieren?

  Alt 2. Jan 2006, 22:07
Im OnDrawCell mach ich folgendes:

Delphi-Quellcode:
procedure TMainForm.StringGrid_AblaufDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  with (Sender as TStringGrid), Canvas do
    begin
      //linke, obere Zelle
      if (ACol = 0) and (ARow = 0) then
        begin
          Brush.Color := clWhite;
        end;

      //erste Zeile und erste Spalte neu zeichnen
      if (ACol = 0) or (ARow = 0) then
        begin
          //Textfarbe Blau
          Font.Color := clBlue;
          Font.Height := 16;
          Font.Style := [fsBold];
          TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
          FrameRect(Rect);
        end
      else
        begin
          //Hintergrundfarbe Weiss
          Brush.Color := clwhite;

          //Textfarbe Schwarz
          Font.Color := clBlack;
          Font.Height := 12;
          Font.Style := [fsBold];
          TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
          FrameRect(Rect);
        end;

      //
      If (ARow > 0) and (ACol > 1) and (ACol < 11) then
        If Cells[ACol, ARow] <> 'then
          begin
            case Cells[ACol, ARow][1] of
              '1': begin
                      //Hintergrund-Farbe "rot" bei Relais einschalten
                      Canvas.Brush.Color := clRed;
                    end;
              '0': begin
                      //Hintergrund-Farbe "rot" bei Relais einschalten
                      Canvas.Brush.Color := clLime;
                    end;
              '?': begin
                      //Hintergrund-Farbe "rot" bei Relais einschalten
                      Canvas.Brush.Color := clYellow;
                    end;
            else
              //Hintergrund-Farbe "weiss"
              Canvas.Brush.Color := clWhite;
            end;

            TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
            FrameRect(Rect);
          end;
    end;
end;
mfg
Helmi

>> Theorie ist Wissen, dass nicht funktioniert - Praxis ist, wenn alles funktioniert und keiner weiss warum! <<
  Mit Zitat antworten Zitat