Delphi-PRAXiS
Seite 1 von 3  1 23      

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/)
-   -   ListBox Items Brush zweifarbig? (https://www.delphipraxis.net/192611-listbox-items-brush-zweifarbig.html)

a.def 4. Mai 2017 15:44

ListBox Items Brush zweifarbig?
 
Ist es möglich einem Item einer ListBox einen zweifarbigen Brush zu geben?

Ich möchte gerne, dass das selektierte Item immer einen ~5px breiten, sich rechts befindlichen, andersfarbigen Balken hat.

Etwa so: [Caption |]

Die Pipe | soll der andersfarbige Teil sein. Der Rest (unter der Caption) ist bei mir blau
Delphi-Quellcode:
TListBox(Control).Canvas.Brush.Color ...

himitsu 4. Mai 2017 16:09

AW: ListBox Items Brush zweifarbig?
 
OnDrawItem -> ListBox.Canvas.irgenwelcherbeliebigerscheiß

a.def 4. Mai 2017 16:18

AW: ListBox Items Brush zweifarbig?
 
Liste der Anhänge anzeigen (Anzahl: 1)
Du verstehst mich falsch :P

ich zeichne meine Items alle schon selber das ist nicht das Problem. Aber ich möchte gerne das selektierte Item zweifarbig haben.
Ich hänge mal ein Bild an.

Das obere ist ja immer so wenn man Brush setzt und das untere ist mein Ziel.

Uwe Raabe 4. Mai 2017 16:23

AW: ListBox Items Brush zweifarbig?
 
Das geht so nicht! Du musst den rechten Streifen zusätzlich drüber malen.

a.def 4. Mai 2017 16:24

AW: ListBox Items Brush zweifarbig?
 
Das dachte ich mir irgendwie schon.

Ich würde dafür ein Shape erzeugen und es einfach dort platzieren oder ist das eher nicht so gut?

himitsu 4. Mai 2017 16:27

AW: ListBox Items Brush zweifarbig?
 
Dann mal doch einfach rechts den grünen Streifen/Rectangle hin. :zwinker:

Ein Brush hat eine gewisse Größe ... soooooo groß, dass er über die gesamte Breite des des Items reicht, wird er nicht sein dürfen.

a.def 4. Mai 2017 16:29

AW: ListBox Items Brush zweifarbig?
 
Ist der Brush denn nicht genau so groß wie das Item selber?
Das mit dem Rectangle verstehe ich nicht. Also im Prinzip doch ein Shape oder sowas?

Edit: sehe gerade ich kann ja die Größe von Rect ändern... ok das klappt dann ja schonmal.
Und dann noch ein Shape?

Warte ich habs jetzt kapiert.
Ich kann den grünen Streifen nicht einfach rechts dran malen denn mein Rect ist (ich habs nicht geändert) so groß wie das Item selber. Das sehe ich wenn ich Rect.Width := Rect.Width-5; mache.
Mein Rect brauche ich um die Hintergrundfarbe des items zu setzen. DAS ist ja das Problem :P

Uwe Raabe 4. Mai 2017 16:37

AW: ListBox Items Brush zweifarbig?
 
Kannst du nicht einfach mal deinen Code zum Zeichnen eines Items zeigen? Dann könnte man gezielt einen Hinweis geben, wie es am einfachsten gehen könnte.

a.def 4. Mai 2017 16:43

AW: ListBox Items Brush zweifarbig?
 
Hier ein Beispiel
Delphi-Quellcode:
// aListBoxBrushColor: array [Boolean] of TColor = (clRed, clWhite);
// aListBoxFontColor: array [Boolean] of TColor = (clInactiveCaptionText, clBlack);


procedure TForm3.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
 oldFontColor: TColor;
 oldFontName: string;
 oldFontS: Byte;
 aLBCanvas: TCanvas;
begin
 aLBCanvas := TListBox(Control).Canvas;

 if odSelected in State then
  begin
   aLBCanvas.Brush.Color := aListBoxBrushSelectedColor;
   aLBCanvas.Font.Color := aListBoxFontSelectedColor;
  end
 else
  begin
   aLBCanvas.Brush.Color := aListBoxBrushColor[Odd(Index)];
   aLBCanvas.Font.Color := aListBoxFontColor[(Enabled)];
  end;

 aLBCanvas.FillRect(Rect);

 oldFontColor := aLBCanvas.Font.Color;
 oldFontS := aLBCanvas.Font.Size;
 oldFontName := aLBCanvas.Font.Name;

 aLBCanvas.TextOut(Rect.Left + 5, Rect.Top + (Rect.Height div 2) - 5, TListBox(Control).Items[Index]);

 if odFocused in State then
  begin
   aLBCanvas.Brush.Color := TListBox(Control).Color;
   aLBCanvas.DrawFocusRect(Rect);
  end;

 aLBCanvas.Font.Color := oldFontColor;
 aLBCanvas.Font.Size := oldFontS;
 aLBCanvas.Font.Name := oldFontName;
end;

Uwe Raabe 4. Mai 2017 16:53

AW: ListBox Items Brush zweifarbig?
 
Setz doch mal folgenden Code hinter das TextOut:

Delphi-Quellcode:
 if odSelected in State then
  begin
   aLBCanvas.Brush.Color := aListBoxBrushSelectedColor2; // die Farbe des rechten Streifens
   aLBCanvas.FillRect(Rect.SplitRect(srRight, 5)); // 5 Pixel am rechten Rand  
  end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:46 Uhr.
Seite 1 von 3  1 23      

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