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. 超过130个你需要了解的vim命令

    基础 :e filename Open filename for edition :w Save file :q Exit Vim :q! Quit without saving :x Write f ...

  2. 腾讯视频嵌入手机端网站demo - 就像微信文章中一样一样的

    页面中的调用如下: <iframe id="video_iframe" class="video_iframe" src="TenVideoPl ...

  3. PHP联合sqlserver2008使用的全过程 ( 原创 亲测)

    一.环境 php5.2.5 sqlserver2008 win7 二.配置PHP 1.打开php.in将extension=php_mssql.dll的注释符号去掉. 2.打开php.in将mssql ...

  4. PYTHON代码摘录

    文件处理 #典型的读取文件代码 row_data = {} with open('PaceData.csv') as paces: column_heading = paces.readline(). ...

  5. TortoiseSVN文件夹及文件图标不显示解决方法 [转]

    由于自己的电脑是win7(64位)的,系统安装TortoiseSVN之后,其他的功能都能正常的使用,但是就是文件夹或文件夹的左下角就是不显示图 标,这个问题前一段时间就遇到了(那个时候没找到合适的答案 ...

  6. iOS+JSPatch在线修改app功能-b

    什么是热更新? 举个例子,你的app上架了,但是突然想添加个小功能,那么你有两种方法 第一种方法:在原生代码中修改源代码,然后提交到appStore,这个过程真是很漫长...虽然最近我提交的都是一两天 ...

  7. JQ实现3D拖拽效果

    <!DOCTYPE HTML> <html onselectstart='return false'> <head> <meta http-equiv=&qu ...

  8. shell 流程控制

    for循环: #!/bin/bash for file in $(ls /ect) do echo $file done

  9. hadoop-streaming 配置之---参数分割

    map: -D stream.map.output.field.separator=. 定义mapoutput字段的分隔符为. 用户可以自定义分隔符(除了默认的tab) -D stream.num.m ...

  10. xss攻击入门

    xss表示Cross Site Scripting(跨站脚本攻击),它与SQL注入攻击类似,SQL注入攻击中以SQL语句作为用户输入,从而达到查询/修改/删除数据的目的,而在xss攻击中,通过插入恶意 ...