How to scroll TTreeView programmatically?

and. Build a Delphi VCL Forms application.

C. Place a TTreeView on the form, name it tvTestand fill it with elements and set the size of the Treeview, so the scrollbars are visible in the TreeView, for example:

enter image description here

C. Put the button on the form and write this code in your click handler:

  procedure TForm1.btnScrollClick(Sender: TObject);
  begin
    tvTest.ScrollBy(tvTest.Width, 0);
  end;

D. Now run the program and click the button. The supposedly horizontal scrollbar should scroll from left to right. But nothing happens. Why?

So, how can I scroll the scroll bars (and of course the contents), scroll left to right, right to left, down or up?

Delphi 10.1 Berlin Update 2
Windows 7 x64 SP1

EDIT . When I use this code (similar to Sami's suggestion):

tvTest.ScrollBy(-3, -3);

... :

enter image description here

+4
1

TreeView, ( Perform) WM_VSCROLL / WM_HSCROLL.

tvTest.Perform(WM_HSCROLL, MakeWParam(SB_LINERIGHT, 0), 0);

tvTest.Perform(WM_VSCROLL, MakeWParam(SB_LINEDOWN, 0), 0);

. .

ScrollBy VCL ScrollWindow API, . , , , () . . , .

+4

Source: https://habr.com/ru/post/1662334/


All Articles