Delphi TListview OwnerDraw SubItems - 更改默认字体(在画布上绘制后,它是大胆的) [英] Delphi TListview OwnerDraw SubItems - change default font (it's bold somehow after you Draw on the canvas)

查看:149
本文介绍了Delphi TListview OwnerDraw SubItems - 更改默认字体(在画布上绘制后,它是大胆的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您使用ownerdraw与TListView,默认情况下,子项目都是BOLD字体样式,即使列表视图font.style设置为[],对于自定义绘制后的所有子项。

If you use ownerdraw with a TListView, the subitems are all BOLD font style by default somehow, even if the listview font.style is set to [], for all the SubItems following a custom drawn one.

我发现的解决方法是强制CustomDrawSubItem事件中的Style设置:

A workaround I found is forcing the Style set in the CustomDrawSubItem event:

ListView2.Canvas.Font.Style := [fsItalic];
ListView2.Canvas.Font.Style := [];

(使用[]的简单调用将不起作用,除非将默认样式设置为[],因为SetStyle调用不认为样式已经改变)

(a simple call with [] won't work unless the default style is set to something other than [], because the SetStyle call doesn't think the style has changed)

然而,这是一个丑陋的修复,涉及额外的处理时间。有更好的解决方案吗?

This is however an ugly fix which involves extra processing time. Is there a better solution?

演示项目: http: //www.mediafire.com/?v8bsdpvpfqy47vn

推荐答案

我没有遇到你所描述的确切情况,但我遇到了类似的问题。当我使用所有者绘制的 TListView 与一个 OnAdvancedCustomDrawSubItem 事件分配更改 Canvas。字体根据每个子项,我发现,在我为一个子项更改了 Sender.Canvas.Font 之后,后续子项将被绘制即使我为他们更改了 Sender.Canvas.Font ,设置错误。我的解决方法是在我的 OnAdvancedCustomDrawSubItem 事件处理程序的末尾手动调用 Sender.Canvas.Font.OnChange 事件处理程序。这些信号 TListView 向Windows报告 CDRF_NEWFONT ,然后一切都正确绘制。就像 Sender.Canvas.Font.OnChange 事件没有正确连接,而 TListView 正在拥有 - 绘制,因此它不会检测到字体更改,因此不会正确地报告回Windows。

I haven't encountered the exact situation you describe, but I have encountered a similar issue. When I use an owner-drawn TListView with an OnAdvancedCustomDrawSubItem event assigned to change the Canvas.Font on a per-subitem basis, I find that after I have changed the Sender.Canvas.Font for one subitem, subsequent subitems get drawn with the wrong settings even if I change the Sender.Canvas.Font for them. My workaround is to manually call the Sender.Canvas.Font.OnChange event handler at the end of my OnAdvancedCustomDrawSubItem event handler. That signals TListView to report back CDRF_NEWFONT to Windows, then everything gets drawn correctly. It is as if the Sender.Canvas.Font.OnChange event is not hooked up correctly while TListView is being owner-drawn, so it does not detect font changes and thus does not report back to Windows correctly.

这篇关于Delphi TListview OwnerDraw SubItems - 更改默认字体(在画布上绘制后,它是大胆的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆