Autor Beitrag
JoBoCAD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Fr 15.09.17 15:15 
Hallo Zusammen,

ich möchte bestimmte Zellen eines Stringgrids nach Klick auf einen
Button einfärben.

Wie ist denn hier die Vorgehensweise.
Hat jemand ein Beispiel.

Danke Euch im Voraus

Gruß
Joe
GuaAck
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 376
Erhaltene Danke: 32

Windows 8.1
Delphi 10.4 Comm. Edition
BeitragVerfasst: Fr 15.09.17 19:02 
Lies mal in dem Tutorial (pdf, 100.57 KB) nach, da steht was darüber,
Gruß
GuaAck

Moderiert von user profile iconNarses: Attachment-Link eingefügt.
Einloggen, um Attachments anzusehen!
JoBoCAD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mo 18.09.17 10:25 
Hallo,
danke für die Info.

Habe es gleich getestet.
Meine Frage.
Wie weise ich dem Stringgrid die Eigenschaften zu ?




Hier der Versuch:
-----------------
unit Unit3;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls;

type
TForm3 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);

private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form3: TForm3;


implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
type
TXEigenschaften = Record // Speichert die Eigenschaften einer Zelle
Farbe : TColor; // Schrift
end;
var EigenschaftenGrid : array [0..5,0..5] of TXEigenschaften;

begin
EigenschaftenGrid[2,2].Farbe:=clred;
form3.StringGrid1.Cells[2,2]:='-';
stringgrid1.Repaint;
end;

end.
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 762
Erhaltene Danke: 127



BeitragVerfasst: Mo 18.09.17 17:25 
Probiere mal das Folgende, das müsstest Du zumindest abwandeln können:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
procedure TForm1.FormCreate(Sender: TObject);
var x, y : Integer;
begin
  for y:=0 to StringGrid1.RowCount-1 do
    for x:=0 to StringGrid1.ColCount-1 do
      StringGrid1.Cells[x, y]:='0';
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var Farbe : TColor;
begin
  if StringGrid1.Cells[ACol, ARow]='0'
    then Farbe:=clBtnHighLight
    else Farbe:=clBlack;
  StringGrid1.Canvas.Brush.Color:=Farbe;
  StringGrid1.Canvas.FillRect(Rect);
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var Zeile, Spalte : Integer;
begin
  Spalte:=(x-1div 11;
  Zeile:=(y-1div 11;
  if StringGrid1.Cells[Spalte, Zeile]='0'
    then StringGrid1.Cells[Spalte, Zeile]:='1'
    else StringGrid1.Cells[Spalte, Zeile]:='0';
end;


Ich färbe hier die Zellen in Abhängigkeit vom Inhalt der Zellen (0 oder 1). Da müsstest Du die Vorgehensweise für Deine Anforderungen abändern.

ub60