I have a scrollable panel (a Panel with AutoScroll = true
).
I also have a control inside the scrollable panel called exampleControl
I need to get the .Top property of exampleControl. When I do exampleControl.Top
, it returns the absolute position.
For example, the panel's height is 500, and it scrolls up to 1000. exampleControl.Top
is 800, so when I get the .Top property, it returns 800 as expected.
What I want to do is get the relative position, meaning that if the panel is scrolled to the bottom, to the point where the exampleControl appears to be 100 away from the top of the panel, then it should return 100.
How do I do this?
CodePudding user response:
Use the AutoScrollPosition.
Here's an example:
int relativeTop = exampleControl.Top - panel.AutoScrollPosition.Y