How to disable horizontal scrollbar for table panel in winforms

前端 未结 9 1105
栀梦
栀梦 2020-12-10 11:54

Hi I\'ve a tablelayoutpanel and I\'m binding controls to it dynamically. When the item count exceeds the height of panel obviously vertical scroll bar appearing there is no

9条回答
  •  醉话见心
    2020-12-10 12:16

    None of these solution worked in every case; I ended up needing a combination of them:

    public void hideHorizontalScrollBar(ref TableLayoutPanel pan)
    {
        if (!pan.HorizontalScroll.Visible)
            return;
        pan.Padding = new Padding(0, 0, 0, 0);
        while (!!pan.HorizontalScroll.Visible || pan.Padding.Right >= SystemInformation.VerticalScrollBarWidth * 2)
        pan.Padding = new Padding(0, 0, pan.Padding.Right + 1, 0);
    }
    

    Important: this can be called once on form load, but must also be called in the layout resize event.

提交回复
热议问题