Einzelnen Beitrag anzeigen

mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.828 Beiträge
 
Delphi 10.4 Sydney
 
#12

Re: Zum verzweifeln- Farbe in den Cells

  Alt 13. Okt 2008, 21:46
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    Col: Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i, j: Integer;
begin
    for i := 0 to 4 do
    begin
        Col := i;
        StringGrid1.Repaint;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    Col := 0;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
    if (ACol = Col) then
    begin
       StringGrid1.Canvas.Brush.Color := clRed;
       StringGrid1.Canvas.FillRect( Rect);
    end
    else
    begin
      StringGrid1.Canvas.Brush.Color := clWhite;
    end;

end;

end.
Markus Kinzler
  Mit Zitat antworten Zitat