首页 > 解决方案 > 虚拟树视图将垂直滚动条放在 RightToLeft 双模的右侧

问题描述

是否可以将虚拟树视图的垂直滚动条放在 RightToLeft 双模的右侧,并将其放在 LeftToRight 模式的左侧?

标签: delphivirtualtreeview

解决方案


为什么不?如果TVirtualTreeView使用系统滚动条,可以通过设置适当的扩展样式来完成。

procedure TForm1.Button2Click(Sender: TObject);
const
  LSB = WS_EX_LEFTSCROLLBAR;
var
  ExStyle: LONG_PTR;
begin
  ExStyle := GetWindowLongPtr(AVTV.Handle, GWL_EXSTYLE);

  // Check if RTL alignment specified for you component
  if AVTV.BiDiMode = bdRightToLeft then
    begin
      // If so, then exclude LSB-constant and allow Windows place 
      // scrollbar on the right side of window
      if (ExStyle and LSB) = LSB then
        SetWindowLongPtr(AVTV.Handle, GWL_EXSTYLE, ExStyle and not LSB);
    end
  else
  if AVTV.BiDiMode = bdLeftToRight then
    begin
      // The same as operation above but for LTR order
      if (ExStyle and LSB) <> LSB then
        SetWindowLongPtr(AVTV.Handle, GWL_EXSTYLE, ExStyle or LSB);
    end;
end;

LSB 常量用于使代码在后期更加紧凑。

也可以看看


推荐阅读