0
votes

I'm using Delphi 10.3 in a VCL app with a Dark VCL style (default Windows10 Dark for example).

I have two problems with VCL styling in TListview

When editing an item in TListview, the listview's edit is not styled: it has a white background with black text. It there any way to apply the VCL style to that edit although it not a VCL control?

Also, with HideSelection = False and the listview not having focus, the selected item's background color is the default light gray color instead of a much darker color that would better fit in the VCL style. Is there any way to modify that other than custom drawing?

I checked this with several dark VCL styles, they all have these problems with TListView (and TTreeview too).

1

1 Answers

1
votes

I was able to fix the listview's edit background and text color by overriding message handler WM_CTLCOLOREDIT in a TListView descendant (TListViewEx in my case) like below. If you check the VCL source for TCustomListView.WMCtlColorEdit you'll see this fix does not cover the case glassPaint case correct - but I'm not using that. It seems to me this is actually a VCL bug and the below code should have been included in TCustomListView.WMCtlColorEdit. Note: the same type of fix also works for TTreeview (using a TTreeview descendant obviously)

I have not found a workaround for the unfocused selection color yet.

procedure TListViewEx.WMCtlColorEdit(var Message: TMessage);
var
  DC: HDC;
begin
  if StyleServices.IsSystemStyle then
    inherited
  else
  begin
    DC := Message.WParam;
    SetTextColor(DC, StyleServices.GetSystemColor(clWindowText));
    SetBkColor(DC, StyleServices.GetSystemColor(clWindow));
    Message.Result := 1;
  end;
end;