I have a TListView
with some specialised areas that display tool tips. Because I cannot by design define specific areas on a TListView
to display more than tool tip per Subitem
.
So I have created a structure that contains their position as will as the tool tip (hint). This part works fine. However, these positions are relative within the TListView
to its top, so once the user has scrolled, the MousePos
still refers to the complete visible of the TListView
, regardless of where the TListView
is scrolled to.
That makes sense; but I wish to add to the Y-coordinate how far the user has scrolled down. (I'd also like to do the same for the X-coordinate, but that is less relevant.) But as far as I can gather there is A) no mechanism on a TListView
to detect this and B) most guides that talk about TListView
and scrolling refer to capturing the scrolling as it is happening, and not in my case, during a different event (in this case, on mouse move).
So how would I detect or calculate how far the user has scrolled while not in a scrolling event?
There's a mechanism: ListView.ViewOrigin
.
Read ViewOrigin to determine the logical origin of the list image. When the list view is not scrolled, ViewOrigin is (0,0). Otherwise, use the x coordinate to determine the number of pixels the view is scrolled horizontally, and the y coordinate to determine the number of pixels the view is scrolled vertically.
var
Pt: TPoint;
begin
Pt := ListView1.ViewOrigin;
This should only work if your listview is in vsIcon
or vsSmallIcon
view style. (You don't seem to have mentioned what view style you're using). Nevertheless with a simple test here, looks like it also works in vsReport
style. ViewOrigin.Y gives exact same value of an 'nPos' of TScrollInfo
retrieved by aGetScrollInfo
call.
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