How to resize a scroll palette

If you open Notepad, add ten lines and resize the editor to only nine, the thumb track (the draggable block on the scroll bar) is almost the full length of the vertical scroll bar. If you add a couple of thousand lines, the thumb track will be just a few pixels.

I would like to duplicate this bahaviour in a descendant of TCustomControl, where I applied a horizontal scrollbar. So I added WS_HSCROLL to my window style (in CreateParams) and implemented a handler for WM_HSCROLL. Along the way, I use SetScrollRange and SetScrollPos to control the range and location of the thumb track - but the small pediatrician remains an almost perfect square.

What am I missing?

+3
source share
2 answers

The documentation is recommended to use SetScrollInforather than SetScrollRangeand SetScrollPos.

As the Wouter answer indicates, you also need to set the page size. The position and range indicate the OS where the center of the thumb is, but the page size tells which part of the range is visible, and that is what determines the size of the thumb. For this you need to use SetScrollInfo; as a bonus, it allows you to immediately set the position, range and page size.


TCustomControl TWinControl : . TScrollingWinControl : . TScrollingWinControl , TCustomControl - VCL. , , .

, , TScrollingWinControl TControlScrollBar .

+4

PageSize, .

:

ScrollBar1.Min      := 0;
ScrollBar1.Max      := 100;
ScrollBar1.Position := 70;
ScrollBar1.PageSize := 50;

:

Page Size

+7

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


All Articles