In a panel i draw controls such as button/textbox positioned starting (0,0) in the panel. These controls are invisible and disabled at the start. I have a button outside the panel that makes these buttons/textbox visible when pressed and position them to a new location in the panel.
The problem is if user scrolled the panel to some (x,y) and then press the 'make visible' button the new (x,y) location of the button is calculated from the current (x,y) location of the panel - not from the top (0,0) of the panel.
I am wondering if this is the correct behavior of panel and that to fix this i need to consider the this.VerticalScroll.Value
as an (x,y) offset when i re-position the buttons.
This is what worked for me. When you get the Y of you button/textbox etc do:
relativeControlTop = theControl.Top - thePanel.AutoScrollPosition.Y;
When you set the top do:
relativeControlTop = theControl.Top + thePanel.AutoScrollPosition.Y;
Hope this Helps.
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