Autor Beitrag
Adrian
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 314



BeitragVerfasst: Do 28.10.04 14:26 
Servus!

Momentan steh' ich auf dem Schlauch und komme einfach nicht weiter...
In meiner Ini-Datei stehen (unter anderem) 29 Positions-Einträge, die zu einem bestimmten Zeitpunkt ausgelesen und angezeigt werden sollen. Zugleich enthält die Ini auch die Information, welche Farbe jeder Position hat.
Und jetzt kommt mein Problem:
Mit was kann ich die Positions-Einträge farbig auf meinem Formular ausgeben?
Zur Zeit verwende ich eine ListBox mit
ausblenden Delphi-Quelltext
1:
ini.ReadSectionValues('Sensorpositionen',Form2.ListBox1.Items);					

was auch wunderbar klappt, aber da fehlt mir halt die Farbdarstellung. Eine Möglichkeit wäre der Einsatz von Labels, aber das habe ich noch nicht realisiert, weil ich der Meinung bin, daß es etwas Besseres geben müßte.
Ich hoffe, ihr wißt, was ich suche...

Gruß,

Adrian

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 28.10.04 15:35 
Du kannst im OnDrawItem der ListBox die Farbe des jeweiligen Eintrages mit Canvas festlegen. Vergiss nicht, Style umzustellen.

Kurzes Bsp:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox) do
  begin
    if Odd(Index) then
    begin
      Canvas.Brush.Color:=clRed;
      Canvas.Font.Color:=clWhite;
    end else
    begin
      Canvas.Brush.Color:=clWhite;
      Canvas.Font.Color:=clGray;
    end;
    Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Items[Index]);
    Canvas.FrameRect(Rect);
  end;
end;


Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Adrian Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 314



BeitragVerfasst: Do 28.10.04 17:51 
Servus!

@.Chef: Prima, genau das war's! :D

Gruß,

Adrian