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);
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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With