AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Formatieren einzelner Zellen in einem StringGrid
Thema durchsuchen
Ansicht
Themen-Optionen

Formatieren einzelner Zellen in einem StringGrid

Offene Frage von "KahPee"
Ein Thema von KahPee · begonnen am 26. Dez 2009 · letzter Beitrag vom 26. Dez 2009
 
Benutzerbild von Wolfgang Mix
Wolfgang Mix

Registriert seit: 13. Mai 2009
Ort: Lübeck
1.222 Beiträge
 
Delphi 2005 Personal
 
#2

Re: Formatieren einzelner Zellen in einem StringGrid

  Alt 26. Dez 2009, 12:21
Vielleicht hilft Dir dieser Codeschnipsel. Den habe ich schon öfter mißbraucht

Delphi-Quellcode:
procedure TForm3.FormCreate(Sender: TObject);
var
  Col, Row: integer;
begin
  // Set the sizes of the arrays
  SetLength(FG, Grid.ColCount, Grid.ColCount);
  SetLength(BG, Grid.ColCount, Grid.ColCount);
  // Initialize with default colors
  for Col := 0 to Grid.ColCount - 1 do begin
    for Row := 0 to Grid.RowCount - 1 do begin
      FG[Col, Row] := clBlack;
      BG[Col, Row] := clWhite;
    end;
  end;

end;

procedure TForm3.GridClick(Sender: TObject);
var
  Col, Row: integer;
  Colo1, Colo2, Colo3: byte;
begin
  Col := Grid.Col;
  Row := Grid.Row;
  // Calculate contrasting random colours
  Colo1 := 200 + Random(56);
  Colo2 := 200 + Random(56);
  Colo3 := 100 + Random(156);
  BG[Col, Row] := RGB(Colo1, Colo2, Colo3);
  FG[Col, Row] := RGB(255 - Colo3, 255 - Colo1, 255 - Colo2);
  // Set the text to be displayed
  Grid.Cells[Col, Row] := 'clicked';

end;


procedure TForm3.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect;State: TGridDrawState);
var S: string;
begin

  S := Grid.Cells[ACol, ARow];
  // Fill rectangle with colour
  Grid.Canvas.Brush.Color := BG[ACol, ARow];
  Grid.Canvas.FillRect(Rect);
  // Next, draw the text in the rectangle
  Grid.Canvas.Font.Color := FG[ACol, ARow];
  Grid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, S);
end;

Gruß

Wolfgang
Wolfgang Mix
if you can't explain it simply you don't understand it well enough - A. Einstein
Mein Baby:http://www.epubli.de/shop/buch/Grund...41818516/52824
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz