autoscroll panel to bottom

后端 未结 3 1933
灰色年华
灰色年华 2020-12-20 14:22

i have a panel in my winforms and in it i load some usercontrols .

i would like to autoscroll to the bottom of the panel( as my panel fills ) everytime a new userco

相关标签:
3条回答
  • 2020-12-20 14:57

    You can do that by setting the VerticalScroll of the Panel but I think it would be better to use ScrollControlIntoView instead.

    private void panel1_ControlAdded(object sender, ControlEventArgs e)
    {
        panel1.ScrollControlIntoView(e.Control);
    }
    

    Good luck!

    0 讨论(0)
  • 2020-12-20 15:00

    I found that continuously adding controls to the panel at vertical increments would be affected negatively whenever a user had scrolled the panel up or down. I used the tip from Homam above, and found the following to work well:

    panel1.VerticalScroll.Value = 0;
    
    // Creating and adding a TextBox, tb, to the panel
    
    panel1.ScrollControlIntoView(tb);
    

    So first, I scroll to the top in order to use absolute vertical positions for my text boxes, then I place the Text Box, and finally, I make sure that the newly created text box comes into view.

    0 讨论(0)
  • 2020-12-20 15:10

    You could use ScrollControlIntoView and pass the control you last added.

    An alternate solution would be:

    panel.VerticalScroll.Value = panel.VerticalScroll.Maximum
    
    0 讨论(0)
提交回复
热议问题