have a problem with a FlowLayoutPanel and I don't know how to solve it.

I'm placing two FlowLayoutPanels inside another; the second inner flp has 3 buttons inside.

The properties from FlowLayoutPanel child are:

FlowDirection=LeftToRight;AutoSize=true;AutoSizeMode=GrowAndShrink;WrapContents=true;

Now I set for each button the FlowBreak property to true, however the behavior I see is not the one I want, I want the FlowLayoutPanel to shrink to the width of the buttons,

Changing FlowDirection to UpToDown is not an option.

Anyone know why the AutoSize is not working?

this is the code.

////FlowLayoutPanel1//this.FlowLayoutPanel1.AutoSizeMode=System.Windows.Forms.AutoSizeMode.GrowAndShrink;this.FlowLayoutPanel1.Controls.Add(this.FlowLayoutPanel3);this.FlowLayoutPanel1.Location=newSystem.Drawing.Point(84,77);this.FlowLayoutPanel1.MinimumSize=newSystem.Drawing.Size(10,10);this.FlowLayoutPanel1.Name="FlowLayoutPanel1";this.FlowLayoutPanel1.Size=newSystem.Drawing.Size(308,265);this.FlowLayoutPanel1.TabIndex=0;////FlowLayoutPanel3//this.FlowLayoutPanel3.AutoSize=true;this.FlowLayoutPanel3.AutoSizeMode=System.Windows.Forms.AutoSizeMode.GrowAndShrink;this.FlowLayoutPanel3.Controls.Add(this.Button1);this.FlowLayoutPanel3.Controls.Add(this.Button2);this.FlowLayoutPanel3.Controls.Add(this.Button3);this.FlowLayoutPanel3.Location=newSystem.Drawing.Point(127,3);this.FlowLayoutPanel3.MinimumSize=newSystem.Drawing.Size(10,10);this.FlowLayoutPanel3.Name="FlowLayoutPanel3";this.FlowLayoutPanel3.Size=newSystem.Drawing.Size(162,87);this.FlowLayoutPanel3.TabIndex=1;////Button1//this.FlowLayoutPanel3.SetFlowBreak(this.Button1,true);this.Button1.Location=newSystem.Drawing.Point(3,3);this.Button1.Name="Button1";this.Button1.Size=newSystem.Drawing.Size(75,23);this.Button1.TabIndex=0;this.Button1.Text="Button1";this.Button1.UseVisualStyleBackColor=true;////Button2//this.FlowLayoutPanel3.SetFlowBreak(this.Button2,true);this.Button2.Location=newSystem.Drawing.Point(3,32);this.Button2.Name="Button2";this.Button2.Size=newSystem.Drawing.Size(75,23);this.Button2.TabIndex=1;this.Button2.Text="Button2";this.Button2.UseVisualStyleBackColor=true;////Button3//this.Button3.Location=newSystem.Drawing.Point(3,61);this.Button3.Name="Button3";this.Button3.Size=newSystem.Drawing.Size(75,23);this.Button3.TabIndex=2;this.Button3.Text="Button3";this.Button3.UseVisualStyleBackColor=true;
////

It is a bug, it's been around for a very long time. The issue is that the layout engine for FlowLayoutPanel calculates the width of the first row wrong, including the width of the 2nd control, even though it got wrapped to the second row.

The workaround is silly but effective, add a dummy Panel with a Width of 0 after the 1st control. If you are doing this with the designer then drop it first and drag it in the right place, to the right of the 1st control. Then set its Margin to (0, 0, 0, 0) and Size to (0, 0) in the Properties window.

////

I don't believe the FlowLayoutPanel was designed to do what you're trying to do. A TableLayoutPanel would probably be better suited. Add a TableLayoutPanel with a single column, and add each button to a row.

Edit: I found a hackish work around. After the first button, create a Panel with the size of 0,0 and the margin of 0,0. Make sure that FlowBreak is set to false.

Edit: You only need to create one panel, after the first button, not one for each.

How to get FlowLayoutPanel.AutoSize to work with FlowBreak的更多相关文章

  1. FlowLayoutPanel autowrapping doesn't work with autosize

    There is no such thing like impossible in software development. Impossible just takes longer. I've i ...

  2. C# Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面

    个人理解,开发应用程序的目的,不论是B/S或是C/S结构类型,无非就是实现可供用户进行查.增.改.删,其中查询用到最多,开发设计的场景也最为复杂,包括但不限于:表格记录查询.报表查询.导出文件查询等等 ...

  3. Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面 z

    http://www.cnblogs.com/zuowj/p/4504130.html 不论是B/S或是C/S结构类型,无非就是实现可供用户进行查.增.改.删,其中查询用到最多,开发设计的场景 也最为 ...

  4. [WinForm] TableLayoutPanel和FlowLayoutPanel的使用

    这篇文章主要跟大家分享下,在配餐系统的开发中,对tableLayoutPanel 和 flowLayoutPanel 控件的使用方法和技巧 ——后附上 测试demo, 相信需要的朋友下载看后能很快的知 ...

  5. FlowLayoutPanel

    动态生成控件  按顺序规律排列时 用panel的话 要指定特定的位置 .麻烦. 可以通过用flowLayoutPanel来解决. FlowLayoutPanel:表格布局面板,适合以表格形式规则的动态 ...

  6. WinForms中的Label的AutoSize属性

    当大量使用UserControl组合UI时,如果更改了Label的Text属性,Label.AutoSize属性会影响UserControl的OnLoad事件的发生顺序; public overrid ...

  7. Add controls dynamically in flowlayoutpanel

    For a FlowLayoutPanel, you don't need to specify a location since the controls are arranged for you. ...

  8. FlowLayoutPanel 内的控件怎么调换顺序?

    lowLayoutPanel1.Controls.SetChildIndex("flowLayoutPanel中的控件",顺序索引)

  9. 动态生成PictureBox控件,涉及:PictureBox控件和flowLayoutPanel面板

    一.概述 flowLayoutPanel面板是一系列控件的容器,有关详细的使用方法留待以后总结. 二.问题提出 问题提出:点击按钮,扫描指定文件夹并将其中的所有图片放在flowLayoutPanel面 ...

随机推荐

  1. jsonp使用规范

    这两天花了很多时间弄研究jsonp这个东西, 可是无论我怎么弄..TMD就是不进入success函数,并且一直进入error函数...让我着实DT啊. 可以看下我之间的提问(这就是我遇到的烦恼).. ...

  2. 星级评论jq

    html结构 <div class="list_item"> <span>商品包装满意度:</span> <b class="s ...

  3. struts2,登录功能模块实现

    功能: ·UserLogin作为控制登录的Action,校验密码成功后记录session,可以选择记住登陆状态,登陆成功后自动跳转到登陆前的URL: ·UserLogout作为控制登录推出的Actio ...

  4. shell中的重定向(2>&1)

    shell的输出可以分为标准输出和错误输出,2>&1中,2代表错误输出,1代表标准输出,&符号代表后面跟的是代号而不是文件. test.sh echo '我是标准输出' ls / ...

  5. MVC-内容详情页显示内容

    @model InfoDataProvider.DataModel.FAQ_ContentUser 内容Content字段:如果里面有html标签. @Html.DisplayFor(p => ...

  6. UML_时序图画法

    UML建模之时序图(Sequence Diagram) 一.时序图简介(Brief introduction) 二.时序图元素(Sequence Diagram Elements) 角色(Actor) ...

  7. js函数语法

    <script type="text/javascript">    //1 普通方法  /*   *  function 方法名(参数){   *   方法体   * ...

  8. c# 获取MP3和AMR文件格式的时长

    //网上摘录整理private long GetAMRFileDuration(string fileName) { ; FileStream fs = new FileStream(fileName ...

  9. ExtJS4.2学习(14)基于表格的扩展插件(2)(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-26/184.html --------------- ...

  10. display:inline-block的深入理解

    在使用 CSS 实现表现的时候,会经常接触到 display:inline-block 这一属性,无论是 初接触 Web 标准还是接触标准已久的朋友,大都会对这一属性感觉很迷惑和模糊. display ...