TableLayoutPanel displays vertical scroll

前端 未结 5 783
有刺的猬
有刺的猬 2020-12-05 05:49

I have TableLayoutPanel for dynamic creation of controls with AutoScroll = true. It\'s work fine when I add new controls. But when I remove and all controls are visible, ver

相关标签:
5条回答
  • 2020-12-05 06:06

    The problem concerns TableLayoutPanel scrolling.
    You have to use a Panel for scrolling instead of TableLayoutPanel.
    Here is an example to solve this problem (for vertical scrolling) :

    • Set your TableLayoutPanel properties as follow :
      • Dock = DockStyle.Top
      • AutoSize = true
      • AutoSizeMode = AutoSizeMode.GrowAndShrink
      • AutoScroll = false.
    • Put your TableLayoutPanel into a Panel with properties :
      • Dock = DockStyle.Fill
      • AutoScroll = true
      • AutoSize = false.
    0 讨论(0)
  • I inserted tableLayoutPanel to XtraScrollableControl(Devexpress control). tableLayoutPanel.Dock set to Top and XtraScrollableControl.Dock to Fill. This solution did not solves this problem, but I got behavior that I need.

    0 讨论(0)
  • 2020-12-05 06:23

    I counted the number of rows in my TableLayoutPanel to see how many would fit. Below the amount that fit I set AutoScroll = false for the add and delete methods. The scroll will appear for large sets and disappear on small sets.

    if (tableLayoutPanel.RowCount < 15)
    {
        panel1.AutoScroll = false;
    }
    else
    {
         panel1.AutoScroll = true;
    }
    
    0 讨论(0)
  • 2020-12-05 06:27

    when you remove the dynamic controls, you need to remove the extra rows that was inserted during the addition and re-size the table layout panel height to smaller than scroll container height.

    During the addition the table layout panel height would have increased, which handled by the scroll container; but when you remove the controls, the table layout panel height doesn't reduce it's height to fit the scroll container.

    One way to do this is to give fixed height to the rows and set the table layout panel seize set to "Auto".

    0 讨论(0)
  • 2020-12-05 06:29

    One of the easiest and funniest solution is to just disable and enable tableLayoutPanel1.AutoScroll

    In your Deleting procedure code add at the end these codes :

        tableLayoutPanel1.AutoScroll = False
        tableLayoutPanel1.AutoScroll = True
    
    0 讨论(0)
提交回复
热议问题