FlowLayoutPanel autowrapping doesn't work with autosize
There is no such thing like impossible in software development. Impossible just takes longer.
I've investigated the problem. If there is really need for Flow Layout, it can be done with a bit of work. Since FlowLayoutPanel lays out the controls without particularly thinking about the number of rows/columns, but rather on cumulative width/height, you may need to keep track of how many controls you've already added. First of all, set the autosize to false, then hook your own size management logic to the ControlAdded/ControlRemoved events. The idea is to set the width and height of the panel in such a way, that you'll get your desired number of 'columns' there
Dirty proof of concept:
privatevoid flowLayoutPanel1_ControlAdded(object sender,ControlEventArgs e){int count =this.flowLayoutPanel1.Controls.Count;if(count %4==0){this.flowLayoutPanel1.Height=this.flowLayoutPanel1.Height+70;}}
if the panel has initially width for 4 controls, it will generate row for new ones. ControlRemoved handler should check the same and decrease the panel height, or get all contained controls and place them again. You should think about it, it may not be the kind of thing you want. It depends on the usage scenarios. Will all the controls be of the same size? If not, you'd need more complicated logic.
But really, think about table layout - you can wrap it in a helper class or derive new control from it, where you'd resolve all the control placing logic. FlowLayout makes it easy to add and remove controls, but then the size management code goes in. TableLayout gives you a good mechanism for rows and columns, managing width and height is easier, but you'd need more code to change the placement of all controls if you want to remove one from the form dynamically.
FlowLayoutPanel autowrapping doesn't work with autosize的更多相关文章
- How to get FlowLayoutPanel.AutoSize to work with FlowBreak
have a problem with a FlowLayoutPanel and I don't know how to solve it. I'm placing two FlowLayoutPa ...
- C# Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面
个人理解,开发应用程序的目的,不论是B/S或是C/S结构类型,无非就是实现可供用户进行查.增.改.删,其中查询用到最多,开发设计的场景也最为复杂,包括但不限于:表格记录查询.报表查询.导出文件查询等等 ...
- Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面 z
http://www.cnblogs.com/zuowj/p/4504130.html 不论是B/S或是C/S结构类型,无非就是实现可供用户进行查.增.改.删,其中查询用到最多,开发设计的场景 也最为 ...
- [WinForm] TableLayoutPanel和FlowLayoutPanel的使用
这篇文章主要跟大家分享下,在配餐系统的开发中,对tableLayoutPanel 和 flowLayoutPanel 控件的使用方法和技巧 ——后附上 测试demo, 相信需要的朋友下载看后能很快的知 ...
- FlowLayoutPanel
动态生成控件 按顺序规律排列时 用panel的话 要指定特定的位置 .麻烦. 可以通过用flowLayoutPanel来解决. FlowLayoutPanel:表格布局面板,适合以表格形式规则的动态 ...
- WinForms中的Label的AutoSize属性
当大量使用UserControl组合UI时,如果更改了Label的Text属性,Label.AutoSize属性会影响UserControl的OnLoad事件的发生顺序; public overrid ...
- Add controls dynamically in flowlayoutpanel
For a FlowLayoutPanel, you don't need to specify a location since the controls are arranged for you. ...
- FlowLayoutPanel 内的控件怎么调换顺序?
lowLayoutPanel1.Controls.SetChildIndex("flowLayoutPanel中的控件",顺序索引)
- 动态生成PictureBox控件,涉及:PictureBox控件和flowLayoutPanel面板
一.概述 flowLayoutPanel面板是一系列控件的容器,有关详细的使用方法留待以后总结. 二.问题提出 问题提出:点击按钮,扫描指定文件夹并将其中的所有图片放在flowLayoutPanel面 ...
随机推荐
- frameset,frame应用,常用于后台
<!DOCTYPE HTML><html><head><title>lin3615</title></head><fram ...
- mysql 数据库备份,恢复。。。。
mysql 数据备份,恢复,恢复没写,这里只写了备份... 先暂作记录吧! 备份:表结构和数据完全分开,默认有一个文件会记录所有表的结构,然后表中数据的备份 如果超过分卷的大小则会分成多个文件,不然则 ...
- DELPHI 取文件名和扩展名
x:=ExtractFileName(str); //取文件名+扩展名,不包含文件路径 y:=ExtractFileExt(str); //取文件的扩展名
- About building ant & install ant on centos7 {ant source code 1.94}
hamcrest-junit-2.0.0.0.jar java-hamcrest-2.0.0.0.jar copy to ant-sourceCodeDir/lib/o ...
- Socket和SignalR
写到一半停电了,这心情真是哔了狗了,草稿箱竟然也没有!!! 好吧,这篇文档是之前写的记录,现在来完善(还是要完善的). 导读: 附件代码实现: Socket: 定义,同步实现,异步实现,还包括了TCP ...
- WPF中三种方法得到当前屏幕的宽和高
WPF程序中的单位是与设备无关的单位,每个单位是1/96英寸,如果电脑的DPI设置为96(每个英寸96个像素),那么此时每个WPF单位对应一个像素,不过如果电脑的DPI设备为120(每个英寸120个像 ...
- Vm image download resource
http://vmdepot.msopentech.com/List/Index http://www.hanselman.com/blog/Over400VirtualMachineImagesOf ...
- Grails连接外部数据库注意事项Could not determine Hibernate dialect for database name [Oracle]!
初次使用Grails时,使用其内置数据库,一直不会出错,但迁移到外部数据库时会出错Could not determine Hibernate dialect for database name [Or ...
- sjtu1364 countcountcount
Description 我有一个元素个数为\(n\)的整数数组\(a\)和\(Q\)个问题,每个问题有\(x,y\)两个参数,我要数有多少个整数\(K\)满足\(K\)在\(a[x]-a[y]\)中出 ...
- UI/UE对个性化推荐的影响
用户界面,用户体验. 在创建网站选择色调时,大多数企业想到的是美观.其实,颜色所起到的作用远超出人们的想象. 关于颜色与购买习惯的心理学书籍比比皆是,下 ...