Autor Beitrag
Maa83
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Fr 21.05.04 14:02 
Hallo,
wie kann man folgendes Problem elegant lösen?

habe eine ComboBox. In diese ComboBox sollen Farbnamen stehen. je nach dem welche Farbe ich auswähle soll sich der Text auch einfärben. (quasi wie z.b. in Word)

also wie ich den Text einfärbe weiss ich nur wie ich das mit der ComboBox genau mache weiss ich nicht.

was ich natürlich machen könnte wäre in die ComboBox die Namen der Farben schreiben und dann abfragen

if cb1.text = 'blau' then TextFrabe := clBlue;
...

das wär zwar möglich aber ich denke ziemlich bescheuert...

hoffe ihr könnt mir helfen

mfg
Martin
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 21.05.04 14:20 
hmm.. besser wäre wohl etwas wie:
ausblenden Delphi-Quelltext
1:
2:
3:
var Palette: Array [0..10of Tcolor=(clblue, clred, $00AAEE22,...);
[..]
TextFarbe:=Palette[cb1.itemindex];

Nicht ausprobiert, aber in etwa so sollte es gehen.
Nur drauf achten, dass im Array genau so viele Elemente drin sind wie in der Combobox, entweder zur Designzeit, oder über ein dynamisches Array zur Laufzeit...

_________________
We are, we were and will not be.
Maa83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Win XP Pro
D6 Ent
BeitragVerfasst: Fr 21.05.04 14:36 
dementsprechend muss ich genau drauf achten das ich im Array die gleiche Reihenfolge habe wie in der ComboBox...
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 21.05.04 19:55 
Jep, aber das sollte ja auch nicht SOO ein Problem sein, oder? Es sei denn, du möchtest zur Laufzeit Farben an beliebiger Stelle hinzufügen, aber sonst:
Einmal n paar Farbnamen überlegen, dazu die passenden Farbwerte, und fertig.

_________________
We are, we were and will not be.