Reputation: 6602
I have FlowLayoutPanel
with multiple controls. Normally horizontal scroll bar is not visible and it is ok. But when I do resize horizontal scroll bar appears and blinks. After resize it is not visible again.
What I tried:
1)
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
flowlayoutPanel.Padding = new Padding(0, 0, vertScrollWidth, 0);
That does not work completely.
2)
flowlayoutPanel.AutoScroll = false;
flowlayoutPanel.HorizontalScroll.Enabled = false;
flowlayoutPanel.HorizontalScroll.Visible = false;
flowlayoutPanel.AutoScroll = true;
After that horizontal scroll bar is disabled, but still visible.
3)
flowlayoutPanel.AutoScroll = true;
flowlayoutPanel.WrapContents = false;
That does not work completely.
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);
}
That does not work completely.
5)
flowlayoutPanel.SuspendLayout();
//resize controls inside flowlayoutPanel
flowlayoutPanel.ResumeLayout();
Much better, horizontal scroll bar blinks less, but still blinks
6)
//ResizeBegin event
flowlayoutPanel.AutoScroll = false;
//ResizeEnd event
flowlayoutPanel.AutoScroll = true;
That does not work completely.
Upvotes: 1
Views: 464
Reputation: 399
I know it is an old post, but I found myself the solution for this problem.
(I did this for VerticalScrollbar
, because this was my problem on a TopDown FlowDirection
FlowLayoutPanel
) but can be transcoded for HorizontalScrollbar
as well.
// 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;
}
So, for hiding 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;
}
Upvotes: 1