使用UseExplorerThemes的VirtualTreeView

时间:2013-09-26 13:59:53

标签: delphi virtualtreeview

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

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

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

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

1 个答案:

答案 0 :(得分:7)

在我看来这是一个错误,因为谁想要这样的选择:

enter image description here

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

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;

你会得到这样的选择:

enter image description here

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

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