AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Listview, CustomDrawSubItem, Text wird schwarz

Listview, CustomDrawSubItem, Text wird schwarz

Ein Thema von FrankJ28 · begonnen am 23. Okt 2011 · letzter Beitrag vom 25. Mai 2018
Antwort Antwort
Seite 1 von 3  1 23   
FrankJ28

Registriert seit: 7. Apr 2008
211 Beiträge
 
Delphi 11 Alexandria
 
#1

Listview, CustomDrawSubItem, Text wird schwarz

  Alt 23. Okt 2011, 11:58
Hallo,
ich habe mit dem folgenden Code das CustomDrwawSubItem-Event befüllt. Der Testrahmen wird auch prima gezeichnet, die normal darzustellenden Spalten jedoch erhalten einen schwarzen Kasten, wenn text enthalten ist, Das aber auch nur, wenn der Cursor/Maus nach unten bewegt wird. Die Richtung nach oben erfolgt korrekt.

Delphi-Quellcode:
procedure TInfoAuftrDlg.PlanViewCustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
var r : TRect;
    i : Integer;
begin
 if SubItem<5
    then begin
          DefaultDraw:=true;
          exit;
         end;
  r := Item.DisplayRect(drBounds);
  for i := 0 to SubItem-1 do begin
    r.Left := r.Left + PlanView.Columns.Items[i].Width;
    r.Right := r.Left + PlanView.Columns.Items[i+1].Width;
  end;
  if SubItem=5
     then PlanView.Canvas.Pen.Color := clRed
     else PlanView.Canvas.Pen.Color := clBlue;

  PlanView.Canvas.Rectangle(r.Left, r.Top, r.Right, r.Bottom);
  DefaultDraw := False;
end;
ListView ist vom Typ vsReport
Jemand eine zündene Idee?
Danke und ciao
Frank
"Sage was du tust, und tue was du sagst"
Johannes Rau
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 23. Okt 2011, 13:19
ich verwende Listview eigentlich nie, aber so bekomme ich das IMHO gewünschte Ergebnis:


(kann sicher noch optimiert werden)

Delphi-Quellcode:
var r : TRect;
    i : Integer;
    s : String;
begin
  PlanView.Canvas.Brush.Color := clWhite;
  PlanView.Canvas.Brush.Style := bsclear;

 if SubItem<1
    then begin
          DefaultDraw:=true;
          exit;
         end;
  r := Item.DisplayRect(drbounds);


  for i := 0 to SubItem-1 do begin
    r.Left := r.Left + PlanView.Columns.Items[i].Width;
    r.Right := r.Left + PlanView.Columns.Items[i+1].Width;
  end;

  if SubItem=1
     then PlanView.Canvas.Pen.Color := clRed
     else PlanView.Canvas.Pen.Color := clBlue;


  PlanView.Canvas.FillRect(r);

  PlanView.Canvas.Rectangle(r.Left, r.Top, r.Right, r.Bottom);
  r.Left := r.Left +1;
  r.Right := r.Right - 1;
  r.Top := r.Top + 1;
  r.Bottom := r.Bottom - 1;
  if item.SubItems.Count >= SubItem then s := item.SubItems[SubItem-1];
  PlanView.Canvas.TextRect(r,s);
  DefaultDraw := false;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
FrankJ28

Registriert seit: 7. Apr 2008
211 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 23. Okt 2011, 13:42
Hallo Thomas,
danke für deinen Einsatz, ich habe mich nur etwas blöd ausgedrückt. Nicht der Text in dem selbstgemalten SubItem, sondern alle Anderen werden schwarz. Un das nur, wenn Cursor oder Maus auf dem Weg nach unten sind, nach oben ist alles sichtbar.
siehe Bild
bild.png
Noch eine Idee?
Ciao
Frank
"Sage was du tust, und tue was du sagst"
Johannes Rau
  Mit Zitat antworten Zitat
DCoderHH

Registriert seit: 4. Feb 2015
Ort: Hamburg
84 Beiträge
 
Delphi 10 Seattle Professional
 
#4

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 09:04
Genau das selbe Problem habe ich jetzt auch mit Delphi Tokyo: Wenn Items ausgewählt werden, wird der Text schwarz, wie auf dem Bildschirmfoto im letzten Post zu sehen. Hat da jemand in den letzten Jahren schon eine Lösung gefunden?
  Mit Zitat antworten Zitat
Whookie

Registriert seit: 3. Mai 2006
Ort: Graz
441 Beiträge
 
Delphi 10.3 Rio
 
#5

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 09:57
Habe das mit 10.2.3 als Minimalbeispiel umgesetzt und es funktioniert bei mir ohne schwarze Felder...
Angehängte Dateien
Dateityp: 7z _ListView_DSI.7z (4,5 KB, 19x aufgerufen)
Whookie

Software isn't released ... it is allowed to escape!
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 10:00
Hier wurde das
Zitat:
This is a workaround for the defective behavior rather than being an answer to the question if there's a bug in the VCL, and a few thoughts.

The workaround is to set the background mode of the device context assigned by the common control for item painting cyle to transparent after carrying out custom drawing:

Delphi-Quellcode:
procedure TForm1.ListViewCustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
var
  R: TRect;
begin
  if not [CustomDrawing] then // <- If we're not gonna do anything do not
    Exit; // fiddle with the DC in any way

  DefaultDraw := False;
  ListView_GetSubItemRect(Sender.Handle, Item.Index, SubItem, LVIR_BOUNDS, @R);
  Sender.Canvas.MoveTo(R.Left, R.Top);
  Sender.Canvas.LineTo(R.Right-1, R.Bottom-1);

  SetBkMode(Sender.Canvas.Handle, TRANSPARENT); // <- will effect the next [sub]item
end;

In an [sub]item paint cycle, the painting is always done in a top-down fashion, items having a lower index are sent NM_CUSTOMDRAW notification prior to ones with higher indexes. When the mouse is moved from one row to another, two rows need to be re-drawn - the one loosing the hot state, and the one gaining it. It would seem, when custom drawing is in-effect, drawing the row that's loosing the hot-state leaves the DC in an undesirable state. This is not a problem when moving the mouse upwards, because that item gets drawn last.

Custom drawing ListView and TreeView controls are different than custom drawing other controls and somewhat complicated (see: Custom Draw With List-View and Tree-View Controls). But you have full control over the entire process. The code in the NM_CUSTOMDRAW case of TCustomListView.CNNotify in 'comctrls.pas' of the VCL is equally complicated. But despite being provided a bunch of custom drawing handlers (half of them being advanced), you have no control over what the VCL does. For instance you can't return the CDRF_xxx you'd like or you can't set the clrTextBk you want. My biased opinion is that, there's a bug/design issue in the Delphi list view control, but I have nothing more concrete than an intuition as in finding a workaround.
als Lösung gepostet.

Gerade seh ich Rot und eine Whookie Lösung... ich schick die Info trotzdem ab
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
DCoderHH

Registriert seit: 4. Feb 2015
Ort: Hamburg
84 Beiträge
 
Delphi 10 Seattle Professional
 
#7

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 12:23
Danke, aber bei beiden Lösungen ist das Problem, dass der Text in der der Spalte, die rechts neben der Owner-Draw-Spalte liegt, pixelig und fett wird. Ein manuelles setzten der Font schafft keine Abhilfe. Die Schrift ist immer pixelig und fett...
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#8

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 12:31
Poste noch mal Dein Projekt damit es nachvollziehen kann.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
DCoderHH

Registriert seit: 4. Feb 2015
Ort: Hamburg
84 Beiträge
 
Delphi 10 Seattle Professional
 
#9

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 12:50
Hier das Projekt zum Testen und ein Screenshot mit dem Fehler (Text wird pixelig und fett)
Miniaturansicht angehängter Grafiken
fehler.png  
Angehängte Dateien
Dateityp: zip _ListView_OwnerDrawTest.zip (3,12 MB, 19x aufgerufen)
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#10

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 14:03
Das ist nicht pixelig und fett, das ist eine andere Schriftart.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:41 Uhr.
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