如何更改 TTNTListView 中某一列的文本颜色?
我在 Delphi 7 中使用 TTNTListView。 它设置为 vsReport。 在 OnCustomDrawSubItem 事件中,我使用以下代码:
procedure TForm.ListViewCustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if SubItem = 2 then
if (Item.SubItems.Strings[1] = Text1) or (Item.SubItems.Strings[1] = Text2) then
Sender.Canvas.Font.Color := clGreen
else
Sender.Canvas.Font.Color := clRed;
end;
问题是所有子项 >= 3 都使用与子项 2 相同的颜色绘制。我检查了 SubItem >= 3 Sender.Canvas.Font.Color 是 clBlack 但它们是绘制的与 clRed 和 clGreen。 如果我的代码有问题,请告诉我如何修复它。 如果这是一个错误,也许有人知道解决方法。 谢谢。
I use a TTNTListView in Delphi 7.
It is set to vsReport.
At OnCustomDrawSubItem event I use this code:
procedure TForm.ListViewCustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if SubItem = 2 then
if (Item.SubItems.Strings[1] = Text1) or (Item.SubItems.Strings[1] = Text2) then
Sender.Canvas.Font.Color := clGreen
else
Sender.Canvas.Font.Color := clRed;
end;
The problem is that all subitems >= 3 are drawn with the same color as subitem 2. I checked and for SubItem >= 3 Sender.Canvas.Font.Color is clBlack but they are drawn with clRed and clGreen.
If it's a problem in my code please show me how to fix it.
If it's a bug maybe someone knows a workaround.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您只需要为其他情况显式设置颜色即可。由于您没有这样做,画布状态仍然存在。试试这个:
I'd guess that you simply need to explicitly set the color for the other cases. Since you aren't doing so the canvas state persists. Try this: