Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Labelfarbe ändern, wenn... (https://www.delphipraxis.net/5234-labelfarbe-aendern-wenn.html)

Chriss 28. Mai 2003 18:10


Labelfarbe ändern, wenn...
 
... etwas bestimmtes drin steht!

Hi @ all

folgendes:
ich habe ein label, in dem steht eine zahl, soweit, so gut... nur, wenn in dem label die zahl größer oder gleich 100 ist, soll die schrift rot, wenn die zahl größer oder gleich 50 ist gelb und wenn die zahl kleiner oder gleich 49 ist grün werden.
nur funkts das nicht, die schrift ist IMMER rot...
vielleicht hab ich im quelltext auch nen fehler gemacht?!:
Code:
if ges_mo.caption>='100' then
begin
ges_mo.font.color:=clred;
end
else
if ges_mo.caption>='50' then
begin
ges_mo.font.color:=clyellow;
end
else
if ges_mo.caption<='50' then
begin
ges_mo.font.Color:=clgreen;
end;
THX

Chriss

CalganX 28. Mai 2003 18:12

Das liegt daran, dass du vergleichst, ob ein String mit einem anderen übereinstimmt (somit kannst du nicht > oder < verwenden).
Du müsstest also schreiben:
Delphi-Quellcode:
if IntToStr(Label1.Caption) >= 100 then // ...
Chris

Chriss 28. Mai 2003 18:15

Fehler:

"Es gibt keine überladene Version von 'IntToStr', die man mit diesen Argumenten aufrufen kann.



Hatte ich schon verscuht!

Christian Seehase 28. Mai 2003 18:17

Moin Chriss,

StrToInt

Chriss 28. Mai 2003 18:24

ahh, danke!!!

:coder:

Jens Schumann 28. Mai 2003 18:34

Hallo,
der Code passt auch ganz gut zum Thema
Delphi-Quellcode:
Label1.Caption:=IntToStr(StrToInt(Label1.Caption)+1);

Marco Haffner 28. Mai 2003 19:35

Re: Labelfarbe ändern, wenn...
 
Zitat:

Zitat von Chriss
Code:
if ges_mo.caption>='50' then
...
else
...
if ges_mo.caption<='50' then

Beim <= reicht auch ein <, denn =50 hast Du ja schon in der mitte überprüft und Du schreibst ja auch, kleiner oder gleich 49.

Chriss 29. Mai 2003 07:53

ich hab nur das problem, dass ich mit den label noch rechnen muss, und sobald ich das mit der farbe mache, gibt der rechenfehler aus... geht also nicht so, wie ichs mir vorgestellt habe, egal, trotzdem danke!

RomanK 29. Mai 2003 10:49

Hoi Chriss.
Zeig mal deinen Code ... weil die Farbe des Labeltextes dürfte da nichts ausmachen... :roll:

Chriss 29. Mai 2003 14:04

es sind mehrere rechnungen drin:

vorrechnung:
Code:
ges_mo.caption:=floattostr(strtofloat(plan_mo_ges_fr.caption)+strtofloat(plan_mo_ges_ab.caption));
dann die endrechnung:
Code:
ges_ges.caption:=floattostr(strtofloat(ges_mo.caption)+strtofloat(ges_di.caption)+strtofloat(ges_mi.caption)+strtofloat(ges_do.caption)+strtofloat(ges_fr.caption)+strtofloat(ges_sa.caption)+strtofloat(ges_so.caption));
so, und da entsteht anscheinend ein konflikt, denn ich will, dass das label ges_mo eingefärbt wird:
rot, wenn über 100
gelb, wenn über 50 und
grün wenn unter 50


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:20 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz