All*_*ain 2 delphi listview brush colors
基本上,我有以下Delphi 2007代码(CustomDrawItem):
procedure TForm1.ListViewCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if (Item.SubItems[0] = '...') then
ListView.Canvas.Brush.Color := clSkyBlue;
end;
Run Code Online (Sandbox Code Playgroud)
在我的Windows XP上,一切都很完美:
但在Windows 7上,这就是我所拥有的:
当然,现在,我想知道填充这些垂直白色条纹的正确代码是什么.但是,我也想知道为什么会这样.它来自德尔福吗?Windows 7的?我的代码?
它似乎是一种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;
Run Code Online (Sandbox Code Playgroud)
Windows 7的
Windows XP