3

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

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

The issue occurs with Delphi 7 and XE2, and probably also with other versions.

To reproduce add a TVirtualStringTree to a form, show the header, add several columns to the header, and activate the options toGridExtensions (MiscOptions), toUseExplorerTheme (PaintOptions), toExtendedFocus (SelectionOptions), run the program and click on any cell.

4

1 回答 1

7

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

在此处输入图像描述

要在虚拟树视图代码中修复它(在我的情况下为 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;

你会得到这样的选择:

在此处输入图像描述

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

我已将此问题报告为Issue 376,已在revision r587.

于 2013-09-26T14:23:40.557 回答