Delphi:列表视图中的Canvas.FillRect
在更改列表视图的子项的文本时,我需要刷涂并填充整行:
procedure TForm1.ListViewDrawItem(Sender: TCustomListView;
Item: TListItem; Rect: TRect; State: TOwnerDrawState);
begin
if Item.SubItems[2]='Done'
then
begin
Sender.Canvas.Font.Color := clBlack;
Sender.Canvas.Brush.Color := clGreen;
Sender.Canvas.Brush.Style := bsSolid;
Sender.Canvas.FillRect(Rect);
end;
end;
但是 Sender.Canvas.FillRect(Rect) 将仅填充子项的矩形。如何填充整行?
这个问题是在 Delphi:如何在 CustomDrawItem 的列表视图中绘制小图标
谢谢!
On change of a text of List View's SubItem I need to brush and fill a whole row:
procedure TForm1.ListViewDrawItem(Sender: TCustomListView;
Item: TListItem; Rect: TRect; State: TOwnerDrawState);
begin
if Item.SubItems[2]='Done'
then
begin
Sender.Canvas.Font.Color := clBlack;
Sender.Canvas.Brush.Color := clGreen;
Sender.Canvas.Brush.Style := bsSolid;
Sender.Canvas.FillRect(Rect);
end;
end;
But Sender.Canvas.FillRect(Rect) will fill only a Rect of the SubItem. How to fill a whole row?
The question is asked on a base of Delphi: how to draw small icons in List View on CustomDrawItem
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您有三列,它们是
Caption
、SubItems[0]
和SubItems[1]
,还记得吗?没有SubItems[2]
!无论如何,这很容易。您只需要对旧代码进行非常非常小的修改。
请特别注意,我使用
clLime
而不是clGreen
,因为clGreen
背景上的clBlack
文本看起来很糟糕!不过,您可以考虑在clGreen
背景上使用clWhite
文本:针对评论进行更新:
要更改列表视图的第三列,仅仅这样做是不行的。
确实,Windows 不知道一列的数据会影响列表视图的外观。整排!
最简单的修复方法是在更改值时告诉 Windows 重新绘制整个控件更好:只需告诉 Windows 重新绘制当前行即可:First, if you have three columns, they are
Caption
,SubItems[0]
, andSubItems[1]
, remember? There is noSubItems[2]
!Anyhow, this is very easy. You only need a very, very small modification of the old code.
Notice in particular that I use
clLime
instead ofclGreen
, becauseclBlack
text on aclGreen
background looks horrible! You might considerclWhite
text on aclGreen
background, though:Update in response to comments:
To change the third column of the list view, it doesn't do to just do
Indeed, Windows doesn't know that the data of one column affects the appearance of the entire row!
The simplest fix is to tell Windows to repaint the entire control when you have changed the valueBetter: just tell Windows to redraw the current row: