Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Aktuelle Zeile in StringGrid farblich hervorheben (https://www.delphipraxis.net/465-aktuelle-zeile-stringgrid-farblich-hervorheben.html)

CalganX 25. Jul 2002 17:26


Aktuelle Zeile in StringGrid farblich hervorheben
 
Hi @all!
Hat jemand eine Idee, wie ich die aktuelle makierte Zeile in einem StringGrid farblich hervorheben kann?

Auf HILFE hoffend,
Chris

Tpercon 25. Jul 2002 21:40

Schau dir mal das OnDraw Ereginis an.

Gruß

jbg 25. Jul 2002 22:04

Kleine Verbesserung: OnDrawCell

Tpercon 26. Jul 2002 09:41

Hast natürlich recht.

CalganX 26. Jul 2002 09:54

Ja, habe ich mir angesehen. Sieht so aus:
Code:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin

end;
Hat jemand vielleicht einen Source?

Chris

jbg 26. Jul 2002 10:10

Der Code hier ist zwar nicht direkt auf dein Problem bezogen, zechnet aber eine bestimmte Zeile in einer anderen Farbe:
Code:
var Grid: TStringGrid;
begin
  Grid := Sender as TStringGrid;

  if gdSelected in State then Grid.Canvas.Font.Color := clBlack;
  if ARow + 1 = DayOfTheWeek(Now) then
  begin
    Grid.Canvas.Brush.Color := RGB(255, 200, 200);
    Grid.Canvas.Font.Style := [fsBold];
  end else Grid.Canvas.Brush.Color := Grid.Color;
  Grid.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Grid.Cells[ACol, ARow]);
end;

CalganX 26. Jul 2002 10:19

@jbg: Erstmal danke, aber leider klappt das nicht so ganz... *sniff*

Chris

jbg 26. Jul 2002 10:35

Zitat:

Zitat von jbg
nicht direkt auf dein Problem bezogen

habe ich geschrieben, also kein Copy&Paste sondern ein "nachdenk" wäre angebrachter.
Aber hier hast du einen für dich passenden Code:
Code:
var Grid: TStringGrid;
begin
  Grid := Sender as TStringGrid;

  if gdSelected in State then
  begin
    Grid.Canvas.Font.Color := clBlack;
    Grid.Canvas.Brush.Color := RGB(200, 200, 255);
    Grid.Canvas.Font.Style := [fsBold];
  end else Grid.Canvas.Brush.Color := Grid.Color;
  Grid.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Grid.Cells[ACol, ARow]);
end;
Jetzt musst du nur noch die Farben anpassen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:37 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz