VirtualTreeView使用UseExplorerThemes的问题

3
我刚刚发现使用toUseExplorerTheme选项可以为VirtualStringTree创建一个漂亮的选择矩形。然而,如果设置了toGridExtensions选项并且树中有多个列,则内部单元格的垂直边框不会绘制,并且圆角也会丢失。只有最左边和最右边列的最外侧边缘和角落被正确绘制。看起来好像选择矩形是在最外面的列之间绘制的,非选定列的背景仅在选择矩形上绘制。
关闭toGridExtensions可以得到正确的选择矩形,但我更喜欢保持它打开,因为在标准模式下只能通过单击文本来选择单元格(不能通过单击文本旁边的空白区域来选择)。
该问题出现在Delphi 7和XE2中,可能也会出现在其他版本中。
要重现,请向窗体添加TVirtualStringTree,显示标题,向标题添加多个列,并激活toGridExtensions(MiscOptions),toUseExplorerTheme(PaintOptions),toExtendedFocus(SelectionOptions)选项,运行程序并单击任何单元格。
1个回答

7

在我看来,这是一个错误,因为谁会喜欢有像这样的选择:

enter image description here

要在Virtual Tree View代码中解决它(在我的情况下是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也是如此。
我已经在问题376中报告了该问题,该问题已在修订版r587中得到解决。

1
不客气!顺便提一句,我之前提供的解决方案存在问题,请更新到修订版r587以获得修复。 - TLama

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接