I'm trying to custom draw a progress bar in a Delphi TListView
as suggested by NGLN's answer to another SO question. This works fine, apart from the interaction with hot tracking when drawn using the new explorer theme introduced in Vista.
The hot tracking painting and the Delphi custom drawing events appear to interfere with each other. For example, the sort of output I am seeing looks like this:
The text in Column 1 should read Item 3 but is obliterated. It looks like a bug in the Delphi wrapper to the list view control, but it could equally be that I'm doing something wrong!
Although I've been developing this in XE2, the same behaviour occurs in 2010 and, presumably, XE.
Here's the code to reproduce this behaviour:
Pascal file
unit Unit1;
interface
uses
Windows, Classes, Controls, Forms, CommCtrl, ComCtrls;
type
TForm1 = class(TForm)
ListView: TListView;
procedure FormCreate(Sender: TObject);
procedure ListViewCustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ListView.RowSelect := True;
ListView.Items.Add.Caption := 'Item 1';
ListView.Items.Add.Caption := 'Item 2';
ListView.Items.Add.Caption := 'Item 3';
end;
procedure TForm1.ListViewCustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
R: TRect;
begin
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);
end;
end.
Form file
object Form1: TForm1
Caption = 'Custom Draw List View Bug'
ClientHeight = 290
ClientWidth = 554
OnCreate = FormCreate
object ListView: TListView
Align = alClient
Columns = <
item
Caption = 'Column 1'
Width = 250
end
item
Caption = 'Column 2'
Width = 250
end>
ViewStyle = vsReport
OnCustomDrawSubItem = ListViewCustomDrawSubItem
end
end
SetBkMode(Sender.Canvas.Handle, TRANSPARENT);
intoTForm1.ListViewCustomDrawSubItem
help? – Sertac Akyuz