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
Benutzerbild von KodeZwerg
KodeZwerg

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

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
 
#2

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.691 Beiträge
 
Delphi 11 Alexandria
 
#3

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
 
#4

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)
Angehängte Grafiken
Dateityp: png Fehler.png (10,3 KB, 35x aufgerufen)
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
 
#5

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
DCoderHH

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

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 14:09
Das ist nicht pixelig und fett, das ist eine andere Schriftart.
OK, aber warum ist es eine andere Schriftart und wie verhindere ich, dass diese für die Darstellung ausgewählt wird?
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Listview, CustomDrawSubItem, Text wird schwarz

  Alt 24. Mai 2018, 14:41
Ich habe alles was nicht zum Projekt gehört gelöscht so das nurnoch Projekt1.dpr, Project1.res, Unit1.dfm, Unit1.pas übrig blieb.
Delphi Tokyo mit der .dpr gestartet, auf Release gestellt, kompiliert, alles hat die gleiche Schrift. Ich kann Fehler nicht reproduzieren.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Antwort Antwort

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 13:31 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz