Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Listbox färbt komisch ein (https://www.delphipraxis.net/121316-listbox-faerbt-komisch-ein.html)

toyoman 25. Sep 2008 15:19


Listbox färbt komisch ein
 
ich weiss ein viel diskutiertes Thema. dennoch komm ich auch nach dem Studium von x threads hier im Forum nicht weiter.
in meiner Listbox möchte ich ausgewählte Einträge einfärben.

habe die listboxdrawitem procedure wie folgt angepasst:

Delphi-Quellcode:
procedure Tmainform.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (control as TListBox) do
  begin
    if Index = 2 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
      Canvas.Rectangle(Rect);
    end;
    Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
end;
der richtige Eintrag wird zwar auch richtig eingefärbt, jedoch ziemlich "verstümelt" - bei allen anderen zeilen habe ich nur noch das Wort des Eintrags markiert und gefärbt. Der Rest ist ein komischer Rahmen und alle sein bisschen schief. Ich weiss nicht wie ich das beschreiben soll?!

habe bei der Listbox eingestellt: lbOwnerDrawFixed

Die Einträge fülle ich normal mit listbox.items.add ein.

kann mir einer sagen warum das so komisch aussieht?

Tyrael Y. 25. Sep 2008 15:39

Re: Listbox färbt komisch ein
 
So besser?


Delphi-Quellcode:
procedure Tmainform.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (control as TListBox) do
  begin
    if Index = 2 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
      Canvas.FillRect(Rect);
    end
    else
    begin
      //falls gewünscht
      Canvas.Brush.Color := clWhite;
      Canvas.Pen.Color := clBlack;
      Canvas.FillRect(Rect);
    end;
    Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
end;

grenzgaenger 25. Sep 2008 15:43

Re: Listbox färbt komisch ein
 
Liste der Anhänge anzeigen (Anzahl: 1)
dann mach doch mal einen screenshoot und häng das mal dran ...

habs mal kurz ausprobiert, mit lbOwnerDrawFixed gibt folgender code das ergebnis lt. anhang...
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
 i: integer;
begin
 for i := 0 to 10 do
  ListBox1.AddItem('item: ' + inttostr(i), NIL);
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
 if control is tListbox then
 begin
  with control as tListbox do
  begin
    if Index mod 2 = 0 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
      Canvas.Rectangle(Rect);
    end;
    Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
 end;
und ich find das ganz in ordnung so ... :stupid:

toyoman 25. Sep 2008 21:05

Re: Listbox färbt komisch ein
 
Zitat:

Zitat von Tyrael Y.
So besser?


Delphi-Quellcode:
procedure Tmainform.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (control as TListBox) do
  begin
    if Index = 2 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
      Canvas.FillRect(Rect);
    end
    else
    begin
      //falls gewünscht
      Canvas.Brush.Color := clWhite;
      Canvas.Pen.Color := clBlack;
      Canvas.FillRect(Rect);
    end;
    Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
end;

ja allerdings, aber ich habe wenn ich mit der maus draufklicke alles weiss (auch die schrift) -> somit unleserlich...
der rahmen mit der farbe passt allerdings...

toyoman 25. Sep 2008 21:06

Re: Listbox färbt komisch ein
 
Zitat:

Zitat von grenzgaenger
dann mach doch mal einen screenshoot und häng das mal dran ...

habs mal kurz ausprobiert, mit lbOwnerDrawFixed gibt folgender code das ergebnis lt. anhang...
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
 i: integer;
begin
 for i := 0 to 10 do
  ListBox1.AddItem('item: ' + inttostr(i), NIL);
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
 if control is tListbox then
 begin
  with control as tListbox do
  begin
    if Index mod 2 = 0 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
      Canvas.Rectangle(Rect);
    end;
    Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
 end;
und ich find das ganz in ordnung so ... :stupid:

sieht bei mir nicht so aus :( sniff

grenzgaenger 25. Sep 2008 21:20

Re: Listbox färbt komisch ein
 
wie siehts denn aus? häng doch mal einen screenshoot an und am besten ein kleines testporjekt dazu (.pas, .dpr und .dfm). ausserdem wäre es ganz interessant, mit welchem betriebssystem das ganze probleme bereitet und ggf. die grafikkarte dazu (hier sind ausgesprochende grfxkartenspezialisten, die gleich sagen können ob es daran liegt).

toms 25. Sep 2008 21:48

Re: Listbox färbt komisch ein
 
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox) do
  begin
    if Index = 2 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.FillRect(Rect);
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
    end
    else
    begin
      //falls gewünscht
      Canvas.FillRect(Rect);
      Canvas.Brush.Color := clWhite;
      Canvas.Pen.Color := clBlack;
    end;
    Canvas.Font.Color := clWindowText; // <- diese Zeile noch hinzufügen. Dann ist die Schrift nicht mehr "weiss"
    Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
end;

toyoman 25. Sep 2008 21:57

Re: Listbox färbt komisch ein
 
Zitat:

Zitat von toms
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox) do
  begin
    if Index = 2 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.FillRect(Rect);
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
    end
    else
    begin
      //falls gewünscht
      Canvas.FillRect(Rect);
      Canvas.Brush.Color := clWhite;
      Canvas.Pen.Color := clBlack;
    end;
    Canvas.Font.Color := clWindowText; // <- diese Zeile noch hinzufügen. Dann ist die Schrift nicht mehr "weiss"
    Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
end;

stimmt, aber jetzt müsst ich noch die Markierte Zeile wieder markieren. Normalerweise ist das glaub ich dunkelblau?
Die ist jetzt transparent und somit sieht man relativ schlecht welche Zeile ausgewählt ist. Der Rest passt schon ganz gut muss ich sagen!
Verwende Vista hier und in der Firma XP. Die Auswirkungen waren bei beiden Systemen die gleichen.

toyoman 25. Sep 2008 21:57

Re: Listbox färbt komisch ein
 
Zitat:

Zitat von grenzgaenger
wie siehts denn aus? häng doch mal einen screenshoot an und am besten ein kleines testporjekt dazu (.pas, .dpr und .dfm). ausserdem wäre es ganz interessant, mit welchem betriebssystem das ganze probleme bereitet und ggf. die grafikkarte dazu (hier sind ausgesprochende grfxkartenspezialisten, die gleich sagen können ob es daran liegt).

wenn das Projekt fertig ist und läuft wird es hier als Freeware oder sogar Opensource veröffentlicht! :)
Ein cooles Tool vorallem für alle Vista Besitzer... :)

toms 25. Sep 2008 22:05

Re: Listbox färbt komisch ein
 
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox) do
  begin
    if Index = 2 then //bei best. Zeile soll folgendes gelten
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Pen.Color := clWhite;
    end
    else
    begin
      //falls gewünscht
      Canvas.Brush.Color := clWhite;
      Canvas.Pen.Color := clBlack;
    end;

     if (odSelected in State) then
     begin
       Canvas.Font.Color := clHighlightText;
       Canvas.Brush.Color := clHighlight;
     end else
       Canvas.Font.Color := clWindowText;

    Canvas.FillRect(Rect);
    Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]);
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:10 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