Search code examples
delphivirtualtreeview

Virtual treeview place the vertical scrollbar on right side in the RightToLeft bidimode


Is it possible to place the vertical scrollbar of Virtual treeview on right side in the RightToLeft bidimode and place it on left side in the LeftToRight mode?


Solution

  • Why not? If TVirtualTreeView uses system scrollbars it could be done with setting appropriate extended style.

    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 constant is used to make code more compact in post.

    See also