Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

painting a button in winform panel while the panel is scrolled

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.

enter image description here

like image 577
Dawit Avatar asked Nov 09 '12 14:11

Dawit


1 Answers

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.

like image 85
Dawit Avatar answered Oct 26 '22 09:10

Dawit