Autor Beitrag
klabri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Mi 19.11.08 14:55 
Hallo,
ich habe ein zweidimensionales Label-Array ,dass zur Laufzeit erstellt wird
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
for x:= 1 to 8 do begin 
for y:= 1 to 8 do begin 
l[x][y]:TLabel.Create(frmMain);
l[x][y].Parent :=frmMain 
l[x][y].Color:=clred; 
l[x][y].OnClick...............????????????
end;
end;


die Labels werden schachbrettartig ausgegeben.
Ich möchte auf ein Label clicken und es soll einfach
nur seine Farbe ändern,von rot nach gelb;
Ich finde nirgendwo eine Lösung für dieses OnClick-Ereignis.
freedy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 403
Erhaltene Danke: 1

Winows 7
Delphi XE
BeitragVerfasst: Mi 19.11.08 15:07 
Hi,

definiere dir einfach selbst eine Prozedur

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure OnLabelClick(Sender : TObject);
begin
  if Sender is TLabel then
  begin 
    TLabel(Sender).Color := clRed; // oder clYellow;
  end;
end;


Die weist du dann einen Labels zu.

Grüße
klabri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Mi 19.11.08 15:22 
Hallo freedy,
dass funktioniert super,danke!!
Dieses Forum ist wirklich super !!
klabri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Mi 19.11.08 15:58 
Hallo,
ich habe noch eine Frage:
ich möchte den x und den y-Wert von l[x][y] bei Click auf das
Label in einer ListBox ausgeben lassen;
freedy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 403
Erhaltene Danke: 1

Winows 7
Delphi XE
BeitragVerfasst: Mi 19.11.08 16:18 
Wenn du das Tag-Property nicht benötigst könntest du folgendes machen:

ausblenden Delphi-Quelltext
1:
  l[x][y].Tag := x * 10 + y;					


Für die Auswertung verfährst du umgekehrt.

ausblenden Delphi-Quelltext
1:
2:
  y := TLabel(Sender).Tag mod 10;
  x := (TLabel(Sender).Tag - y) div 10;


Ob es gut ist, lasse ich mal im Raum stehen. ;-)