Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center panel scroll in control C#

I have a Panel in which i'm adding controls to it dynamically. I want to scroll the Panel to the position of one given control of the Panel

I'm using the ScrollControlIntoView method of the ScrollableControl object as follows:

public void centerPanel(Control p){
        panel.ScrollControlIntoView(p);
    }

But the panel seems to move to random positions.

The AutoScrollproperty is set to True in the Panel.

Any thoughts ?

like image 380
guanabara Avatar asked Nov 13 '22 09:11

guanabara


1 Answers

I have detected my mistake. I was scrolling the Panel before adding the Control to the Panel.

So, here is the correct way to scroll a Panelto a given control.

panel.Controls.Add(control);
panel.ScrollControlIntoView(control);

Thanks.

like image 193
guanabara Avatar answered Nov 15 '22 13:11

guanabara