我有FlowLayoutPanel
多个控件。通常水平滚动条不可见,没关系。但是当我调整水平滚动条的大小时会出现并闪烁。调整大小后再次无法看到。
我尝试了什么:
1)
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
flowlayoutPanel.Padding = new Padding(0, 0, vertScrollWidth, 0);
这不起作用。
2)
flowlayoutPanel.AutoScroll = false;
flowlayoutPanel.HorizontalScroll.Enabled = false;
flowlayoutPanel.HorizontalScroll.Visible = false;
flowlayoutPanel.AutoScroll = true;
之后,水平滚动条被禁用,但仍然可见。
3)
flowlayoutPanel.AutoScroll = true;
flowlayoutPanel.WrapContents = false;
这不起作用。
4)
[DllImport("user32.dll")]
static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
protected override void OnShown(EventArgs e) {
ShowScrollBar(this.flowlayoutPanel.Handle, SB_HORZ, false);
base.OnShown(e);
}
这不起作用。
5)
flowlayoutPanel.SuspendLayout();
//resize controls inside flowlayoutPanel
flowlayoutPanel.ResumeLayout();
更好的是,水平滚动条闪烁较少,但仍然闪烁
6)
//ResizeBegin event
flowlayoutPanel.AutoScroll = false;
//ResizeEnd event
flowlayoutPanel.AutoScroll = true;
这不起作用。
答案 0 :(得分:1)
我知道这是一篇老文章,但我发现自己可以解决此问题。
(我这样做是为了VerticalScrollbar
,因为这是我在TopDown FlowDirection
FlowLayoutPanel
上遇到的问题),但是也可以将其转换为HorizontalScrollbar
。
// pContent is my FlowLayoutPanel, it has FlowDirection set to TopDown
// and WrapContent = true;
pContent.SuspendLayout();
// Populate the FlowLayoutPanel with controls
pContent.ResumeLayout();
// I want to show only HorizontalScrollbar
if (pContent.VerticalScroll.Visible)
{
pContent.AutoScroll = false;
pContent.VerticalScroll.Visible = false;
pContent.Height -= SystemInformation.HorizontalScrollBarHeight;
pContent.AutoScroll = true;
pContent.Height += SystemInformation.HorizontalScrollBarHeight;
}
因此,为了隐藏HorizontalScrollbar:
// pContent has FlowDirection set to LeftRight and WrapContent = true;
pContent.SuspendLayout();
// Populate the FlowLayoutPanel with controls
pContent.ResumeLayout();
// I want to show only VerticalScrollbar
if (pContent.HorizontalScroll.Visible)
{
pContent.AutoScroll = false;
pContent.HorizontalScroll.Visible = false;
pContent.Width -= SystemInformation.VerticalScrollBarWidth;
pContent.AutoScroll = true;
pContent.Width += SystemInformation.VerticalScrollBarWidth;
}