Autor Beitrag
footstep78
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Do 18.01.07 23:06 
Hallo Forum,

ich möchte Einträge in einer ComboBox farbig darstellen.
Es soll nicht nur möglich sein einen Eintrag aus der Liste zu wählen, sondern alternativ selber Text einzugeben wie im Style csDropDown.

Generell gibt es ja die Möglichkeit das Control selbst zu zeichnen und den Schriftstil zu beeinflussen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with ComboBox1 do
  begin
    Canvas.FillRect(Rect);
    case Index of
      0 :  Canvas.Font.Color := clRed;
      1 :  Canvas.Font.Color := clGreen;
      2 :  Canvas.Font.Color := clBlue;
      else Canvas.Font.Color := clBlack;
    end;
    Canvas.TextOut(Rect.Left, Rect.Top, Items[Index]);
  end;
end;

Leider wird OnDrawItem aber ja nur aufgerufen, wenn der Style auf csOwnerDrawFixed oder csOwnerDrawVariable steht und diese lassen keine Eingabe eines eigenen Textes zu :(

Hat jemand eine Idee wie man das realisieren kann oder kennt jemand eine alternative Komponente die das unterstützt?

Ich verwende BDS 2006, es handelt sich um eine Win32-Anwendung.

Vielen Dank für Eure Unterstützung!

footstep

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Ratchet
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Fr 26.01.07 09:37