Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I control the FlowLayoutPanel that I get a horizontal scrollbar when I change WrapContents=true at runtime?

The situation:
In the FlowLayoutPanel are several equal-sized elements.
Flow Direction is TopDown.

Default is WrapContens to false, all elements are displayed below each other, and when the panel size is too small, I get a vertical scrollbar.

The task:
If the width of the FlowLayoutPanel is changed and >= 2 * element width, set WrapContents=true.

The problem:
If I set WrapContens=true at runtime, and the wrap creates more than 2 columns, I get no horizontal scrollbar.

But if WrapContens=true is set at design time, then I get the horizontal scroll bar in the running program.


Thanks for any idea.
Posted

1 solution

Now I found a solution myself, playing around with the FlowLayoutPanel.

The AutoScroll must set to false while changing the WrapContents:

C#
this.AutoScroll = false;
this.WrapContents = this.Width >= this.Controls[0].Width * 2;
this.AutoScroll = true;


Then the correct scroll bars will be displayed.

The behavior is not documented anywhere. Very mysterious.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900