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. 配置Apache+Mysql+Php

    以下操作均在Debian 6.0 64bit 环境root权限下进行,如果提示权限不足请切换至root用户或者sudo,本人比较喜欢自行安装,因为安装的过程中能最小化安装而且能够知道安装了什么,然后可 ...

  2. 3d旋转--transform-style: preserve-3d,translate3d(x,y,z),perspective()

    transform-style: preserve-3d,translate3d(x,y,z),perspective() 让其倾斜的核心:加perspective(600px)让其动的核心:rans ...

  3. 线程池原理及创建并C++实现

    本文给出了一个通用的线程池框架,该框架将与线程执行相关的任务进行了高层次的抽象,使之与具体的执行任务无关.另外该线程池具有动态伸缩性,它能根据执行任务的轻重自动调整线程池中线程的数量.文章的最后,我们 ...

  4. Magento Api 记录

    magento api 首次接触 (-) /** * magento Api 身份验证 调用示例 * Example of simple product POST using Admin accoun ...

  5. 微信支付JS API使用心得

    微信的接口真的很坑爹,只返回成功或失败,从来不会告诉你为什么失败.这个微信支付的js接口也是调了一个下午才成功,期间踩了不少坑,在这里总结一下,而且把支付接口封装成了一个js文件,这样以后调用就很方便 ...

  6. An error occurred while collecting items to be installed session context was:(profile=DefaultProfile... 解决方案

    遇到同样问题的小伙伴请:点击Eclipse上方工具栏中help --> Install new software... --> 看图 点击进红框的位置在打开的窗口中,将窗口右侧的Avail ...

  7. 使用memcache(thinkphp框架学习)

    $memcache = new Memcache; $memcache->connect("localhost",11211); $memcache->set('sxt ...

  8. 服务器环境搭建系列(一)-Apache篇

    一.Apache 1.解压缩tar包httpd-2.2.22.tar.gz,这里默认放在/opt下 tar -zxvf httpd-2.2.22.tar.gz 2.进入解压缩后的文件夹 cd http ...

  9. PPTPD/L2TP/IPSec VPN一键安装包 For CentOS 6

    一.一键安装PPTPD VPN 本教程适用于Openv VPS.Xen VPS或者KVM VPS. 1.首先运行如下命令: cat /dev/net/tun 返回的必须是: cat: /dev/net ...

  10. Fast CGI 工作原理

    http://www.cppblog.com/woaidongmao/archive/2011/06/21/149092.html 一.FastCGI是什么? FastCGI是语言无关的.可伸缩架构的 ...