这似乎是 Windows 7 绘制行为,作为解决方法,您可以将ownerdraw
属性设置为 true 并改用该OnDrawItem
事件。
像这样
uses
CommCtrl;
{$R *.dfm}
procedure TForm7.ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
Rect: TRect; State: TOwnerDrawState);
var
LIndex : integer;
ListView : TListView;
LRect: TRect;
LText: string;
begin
ListView:=TListView(Sender);
for LIndex := 0 to ListView.Columns.Count-1 do
begin
if not ListView_GetSubItemRect(ListView.Handle, Item.Index, LIndex, LVIR_BOUNDS, @LRect) then
Continue;
if Item.Selected and (not ListView.IsEditing) then
begin
ListView.Canvas.Brush.Color := clHighlight;
ListView.Canvas.Font.Color := clHighlightText;
end
else
if (Item.SubItems[0] = '...') then
begin
ListView.Canvas.Brush.Color := clSkyBlue;
ListView.Canvas.Font.Color := ListView.Font.Color;
end
else
begin
ListView.Canvas.Brush.Color := ListView.Color;
ListView.Canvas.Font.Color := ListView.Font.Color;
end;
ListView.Canvas.FillRect(LRect);
if LIndex = 0 then LText := Item.Caption
else LText := Item.SubItems[LIndex-1];
ListView.Canvas.TextRect(LRect, LRect.Left + 2, LRect.Top, LText);
end;
end;
Windows 7的
视窗