delphi - VirtualStringTree 对齐文本和网格线

标签 delphi delphi-7 vcl virtualtreeview tvirtualstringtree

我有一个虚拟字符串树(启用网格线),带有 X 个 header 和 x 个根。 我想将子项(至少 1 个)添加到只有 1 个文本的根中,该文本位于中间并遍历所有标题(独立)。因此,无论我是否调整标题等的大小,文本始终与 VirtualStringTree 的实际客户端大小对齐。

这可能吗?如果是这样,怎么办?

enter image description here

最佳答案

这听起来像是单元格合并。这是讨论的here例如,解决方案是将 toAutoSpanColumns 包含在 TreeOptions.AutoOptions 中。

如果您想要居中对齐文本,请相应地重写OnDrawText。像这样的东西:

procedure TForm1.VirtualStringTree1DrawText(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  const Text: WideString; const CellRect: TRect; var DefaultDraw: Boolean);
var
  r: TRect;
begin
  r := CellRect;
  Windows.DrawTextW(TargetCanvas.Handle, PWideChar(Text), Length(Text), r, DT_CENTER or DT_VCENTER);
  DefaultDraw := False;
end;

关于delphi - VirtualStringTree 对齐文本和网格线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11877505/

相关文章:

arrays - 将本地动态数组的长度设置为零会减少内存使用量吗?

Delphi - 窗体中的窗体

delphi - 将字形和 WordWrap 文本一起绘制

delphi - DrawTextA、Courier New 和日语语言环境的奇怪行为

delphi - 编译时播放声音

Delphi 2010-IDE 不断停止在 CPU 调试窗口

delphi - libvlc vmem 访问冲突

delphi - 如何在 Delphi 7 中设置调试器参数?

Delphi 从 TObjectDictionary 中提取键

C++ 构建器 TstringGrid 从特定单元格获取字符串