Autor Beitrag
mtm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

Windows 10 Pro 64 Bit
Delphi XE 6
BeitragVerfasst: Mo 26.09.11 17:49 
Hallo zusammen,
ich habe ein Problem. Ich möchte für ein Programm ein "Farbsetup" entwerfen, also für 4 verschiedene Programmteile die Farbe (Hintergrund und Text) einstellen. Für die Anzeige benutze ich Panels.

mit folgendem Code soll die Farbe nach drücken eines Buttons geändert werden :
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:
procedure TfrmOption.onColorClick(Sender: TObject);
var
  nr:Integer;
  pnl:TPanel;
  f: TColor;
  txt: String;
begin
  f := clWhite;
  with ColorDialog1 do begin
    if Execute(Self.Handle) then
      f := Color;  // Farbe auswählen
  end;
  nr := TButton(Sender).Tag; // Tag ist richtig gesetzt (mehrfach überprüft)

  txt := 'pnlCol' + IntToStr(nr);  // 
  pnl := TPanel(Self.FindComponent(txt));
  if pnl<>nil then begin
    Self.Caption := pnl.Name + ' / Color : ' + IntToStr(f);  // zu Testzwecken
    pnl.ParentColor := false;  // bin nicht sicher ob benötigt, aber schaden kann's ja eigentlich nicht.
    pnl.Color := f;
  end;
end;


Es passiert aber rein gar nichts. Die Panels sind übrigens nicht per Code sondern manuell im Designfenster auf die Form gebracht worden.
Hat einer von Euch irgendeine Ahnung, woran das liegen kann.
Die Panels werden übrigens mit FindComponent gefunden, die Testzeile (Self.Caption...) wird nämlich ausgeführt.

Danke im Voraus
mtm

Editiert : Gott, bin ich ein Idiot. ParentBackground war noch auf True.
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: Mi 28.09.11 00:11 
Setz mal ParentBackground noch auf false, dann müsste es klappen.

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:
procedure TfrmOption.onColorClick(Sender: TObject);
var
  nr:Integer;
  pnl:TPanel;
  f: TColor;
  txt: String;
begin
  f := clWhite;
  with ColorDialog1 do begin
    if Execute(Self.Handle) then
      f := Color;  // Farbe auswählen
  end;
  nr := TButton(Sender).Tag; // Tag ist richtig gesetzt (mehrfach überprüft)

  txt := 'pnlCol' + IntToStr(nr);  // 
  pnl := TPanel(Self.FindComponent(txt));
  if pnl<>nil then begin
    Self.Caption := pnl.Name + ' / Color : ' + IntToStr(f);  // zu Testzwecken
    pnl.ParentColor := false;  // bin nicht sicher ob benötigt, aber schaden kann's ja eigentlich nicht. //Edit <--<<< doch muss so
    pnl.ParentBackground := false; //Edit// <--<<< 
    pnl.Color := f;
  end;
end;

_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P