【问题标题】:VirtualTreeView with UseExplorerThemes带有 UseExplorerThemes 的 VirtualTreeView
【发布时间】:2013-10-02 13:08:45
【问题描述】:

我刚刚发现使用 Option toUseExplorerTheme 可以为 VirtualStringTree 生成一个不错的选择矩形。但是,如果设置了 Option toGridExtensions 并且树中有几列,则不会为内部单元格绘制选择的垂直边框,并且圆角也会丢失。只有最左侧和最右侧列的最外侧边和角被正确绘制。看起来好像选择矩形是在最外层的列之间绘制的,而未选择的列的背景只是在选择矩形上绘制的。

关闭 toGridExtensions 会产生正确的选择矩形,但我更喜欢打开它,因为只能通过在标准模式下单击文本来选择单元格(而不是单击文本旁边的空白区域) .

Delphi 7 和 XE2 出现此问题,其他版本也可能出现此问题。

要重现将 TVirtualStringTree 添加到表单,显示标题,向标题添加几列,并激活选项 toGridExtensions (MiscOptions)、toUseExplorerTheme (PaintOptions)、toExtendedFocus (SelectionOptions),运行程序并单击任何单元格.

【问题讨论】:

    标签: delphi virtualtreeview


    【解决方案1】:

    在我看来这是一个错误,因为谁愿意有这样的选择:

    要在虚拟树视图代码中修复它(在我的情况下为 v.5.1.4),请转到 TBaseVirtualTree.PrepareCell 方法(在我的情况下为第 25802 行)并检查此嵌套过程代码(cmets 是我的):

    procedure DrawBackground(State: Integer);
    begin
      // here the RowRect represents the row rectangle and InnerRect the cell
      // rectangle, so there should be rather, if the toGridExtensions is NOT
      // in options set or the toFullRowSelect is, then the selection will be
      // drawn in the RowRect, otherwise in the InnerRect rectangle
      if (toGridExtensions in FOptions.FMiscOptions) or (toFullRowSelect in FOptions.FSelectionOptions) then
        DrawThemeBackground(Theme, PaintInfo.Canvas.Handle, TVP_TREEITEM, State, RowRect, nil)
      else
        DrawThemeBackground(Theme, PaintInfo.Canvas.Handle, TVP_TREEITEM, State, InnerRect, nil);
    end;
    

    要解决此问题,请按以下方式修改代码:

    procedure DrawBackground(State: Integer);
    begin
      // if the full row selection is disabled or toGridExtensions is in the MiscOptions, draw the selection
      // into the InnerRect, otherwise into the RowRect
      if not (toFullRowSelect in FOptions.FSelectionOptions) or (toGridExtensions in FOptions.FMiscOptions) then
        DrawThemeBackground(Theme, PaintInfo.Canvas.Handle, TVP_TREEITEM, State, InnerRect, nil)
      else
        DrawThemeBackground(Theme, PaintInfo.Canvas.Handle, TVP_TREEITEM, State, RowRect, nil);
    end;
    

    你会得到这样的选择:

    这同样适用于下一个DrawThemedFocusRect 嵌套过程。

    我已将此问题报告为Issue 376,已在revision r587 中修复。

    【讨论】:

    • 优秀。谢谢。
    • 不客气!无论如何,我之前提出的解决方案有an issue,所以请更新到修订版 r587 进行修复。
    猜你喜欢
    • 1970-01-01
    • 2012-01-18
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 2016-03-13
    • 1970-01-01
    • 2012-06-25
    相关资源
    最近更新 更多