Einzelnen Beitrag anzeigen

Benutzerbild von Lannes
Lannes

Registriert seit: 30. Jan 2005
Ort: Münster
745 Beiträge
 
Delphi 3 Professional
 
#12

Re: StringGrid: Zellen-Farbe bei Click ändern

  Alt 28. Jan 2007, 20:45
Hallo,

falls Du StringGrid.Objects noch nicht anderweitig verwendest,
wäre das folgende denkbar:
Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
const SelColor = ClRed;
begin
  with TStringGrid(Sender), Canvas do
    begin
    if Integer(Objects[aCol,ARow]) = 1 then
      Brush.Color := FocusedColor
      else
        Brush.Color := Color;
    FillRect(Rect);
    TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[aCol, aRow]);
    end;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var ACol,ARow : Integer;
begin
  with TStringGrid(Sender), Canvas do
    begin
    MouseToCell(X,Y,ACol,ARow);
    Objects[ACol,ARow] := Pointer(Integer(Objects[ACol,ARow]) xor 1);
    end;
end;
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
  Mit Zitat antworten Zitat