TListView 项目焦点主题

发布于 2024-11-30 11:30:10 字数 329 浏览 2 评论 0原文

当使用 TListView 并且在应用程序中禁用主题时,聚焦和选定的项目将显示如下所示:

在此处输入图像描述

请注意两个图像中三角形的位置。项目的绘制框不会绘制在图标出现的位置。在 TListBox 中,绘制的项目填充整个选定的项目。

我怎样才能像填充文本部分一样填充所选项目的图标部分?

我知道 TListBox 像这样呈现,但我需要使用 TListView 作为 Data 属性,而且 TListView 通过 TImageList 更好地处理图标。

谢谢。

When using a TListView and themes are disabled in the Application, the focused and selected item appears something like this:

enter image description here

Notice in both images where the triangle is. The painted box for the item does not draw where the icon appears. In a TListBox the painted item fills the whole selected item.

How might I be able to get the icon part of the selected item to fill, just as it does with the text part?

I know TListBox renders like this, but I require the use of TListView for the Data property, also the TListView handles icons better via a TImageList.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2024-12-07 11:30:11

您需要使用 TListView 的 OnCustomDraw 事件。在事件处理程序中:

  1. 确定项目是否被选择
  2. 确定控件是否获得焦点
  3. 如果选择了项目,则绘制适当的选择矩形(如果未选择控件,则为灰色;如果已选择,则为蓝色)
  4. 绘制文本
  5. 从控件中绘制图像imagelist 使用 TImageList.Draw

有一些方法可以完成这些事情,例如 DrawText 和 FillRect。

请注意,如果您愿意,您可以使用 TListBox 而不是 TListView。您表示您需要列表中项目的 Data 属性,我假设将它们与您的实际模型对象联系起来。您可以使用 TStrings 对支持 TStrings 的任何内容(例如 TListBox.Items)执行此操作。对象

You'll need to use the OnCustomDraw events of TListView. Within the event handler:

  1. Determine if the item is selected
  2. Determine if the control is focused
  3. Draw the appropriate selection rectangle if the item is selected (grey if the control isn't selected, blue if it is)
  4. Draw the text
  5. Draw the image from the imagelist using TImageList.Draw

There are methods for doing these things, such as DrawText and FillRect.

Note that you can use TListBox rather than TListView if you'd rather. You indicated you need the Data property for items in the list, I'd assume to tie them up to your actual model objects. You can do this with anything that supports TStrings (such as TListBox.Items) using TStrings.Objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文