Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a scrollbar grip to the very top position with one single command?

It is easy to send a control's scrollbar from the very bottom position to the very top position by sending a WM_VSCROLL message REPEATEDLY to the control:

ScrollBox1.Perform(WM_VSCROLL, MakeWParam(SB_PAGEUP, 0), 0);

enter image description here

But this requires knowing how many times I have to send the message to the control to set the scrollbar to the very top position, depending on the proportional size of the scrollbar grip in relation to the scrollbar's height. Alternatively, I can send the message repeatedly for an irrational amount of times which seems not being the best solution.

So how can I send the scrollbar to the very top with ONE SINGLE command independently from the proportional size of the scrollbar grip in relation to the scrollbar's height?

like image 995
user1580348 Avatar asked Dec 15 '22 02:12

user1580348


1 Answers

To scroll the bar to the top:

ScrollBox1.VertScrollBar.Position := 0;

See Vcl.Forms.TControlScrollBar.Position


Or use the windows API WM_VSCROLL message:

Scroll to top:

ScrollBox1.Perform( WM_VSCROLL, MakeWParam(SB_Top,0),0);

Scroll to bottom:

ScrollBox1.Perform( WM_VSCROLL, MakeWParam(SB_Bottom,0),0);
like image 56
LU RD Avatar answered Dec 22 '22 00:12

LU RD