To make the scrollbar thumb size proportional to the amount of data displayed, we need to set the page size of the scroll bar. If we don’t set the page size for the scroll bar explicitly, the thumb size will be the default size given by windows. This is not proportional to the amount of data displayed on the screen. So we need to set the page size to the scroll bar explicitly.
The page size of the scroll bar can be set using SetScrollInfo function, with the required value of page filled in the corresponding field in a SCROLLINFO structure.
The range of the scroll bar should be (the total size of data displayed -1), and the page size should be the amount of data displayed at a time.
Also, the condition for stopping the scroll is taken from the formulae
MaxScrollPos = MaxRangeValue - (PageSize - 1)
i.e. The maximum scroll position of the scrollbar is dependant on the Range and the page size as said in the above formula. A check based on this can be added in the procedure for scrolling the base area dialog. Otherwise the scrolling may not stop even when all the data has been scrolled up.
Though many developer sites and books said the scroll bar range should be set to (Max height of data -1), I was trying to get why so. And the result? follows :
Total area to be displayed = MaxHt
Total area displayed at a time = PageSize
Area to be scrolled = MaxHt - PageSize
Let's take No. of ScrollBar positions = nPos.
nPos = MaxHt - PageSize ---- (1)
We have nPos = Range - ( PageSize -1 ) ----- (2) [ MSDN ]
= Range - PageSize +1
= Range +1 - PageSize
i.e. nPos = ( Range+1) - PageSize. -------- (3)
From (1) and (3), nPos = MaxHt - PageSize = (Range +1) - PageSize
=> MaxHt = Range +1
=> Range = MaxHt -1
No comments:
Post a Comment