如何获得FlowLayoutPanel.AutoSize与FlowBreak工作 [英] How to get FlowLayoutPanel.AutoSize to work with FlowBreak
问题描述
我有一个FlowLayoutPanel的一个问题,我不知道如何解决它。
我把里面的另外两个FlowLayoutPanels;第二内FLP内部有3个按钮。
这FlowLayoutPanel的孩子的属性是:
的FlowDirection = LeftToRight;
自动调整大小=真;
AutoSizeMode = GrowAndShrink;
WrapContents = TRUE;
现在我为每个按钮设置 FlowBreak
财产我看到真实的,但该行为是不是我想要的,我想要的FlowLayoutPanel的收缩到按钮的宽度,
修改的FlowDirection
为观点操作系统
不是一个选项。
任何人都知道为什么自动调整大小不工作?
这是代码。
//
// FlowLayoutPanel1
//
this.FlowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.FlowLayoutPanel1.Controls.Add(this.FlowLayoutPanel3);
this.FlowLayoutPanel1.Location =新System.Drawing.Point(84,77);
this.FlowLayoutPanel1.MinimumSize =新System.Drawing.Size(10,10);
this.FlowLayoutPanel1.Name =FlowLayoutPanel1;
this.FlowLayoutPanel1.Size =新System.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 =新System.Drawing.Point(127,3);
this.FlowLayoutPanel3.MinimumSize =新System.Drawing.Size(10,10);
this.FlowLayoutPanel3.Name =FlowLayoutPanel3;
this.FlowLayoutPanel3.Size =新System.Drawing.Size(162,87);
this.FlowLayoutPanel3.TabIndex = 1;
//
// Button1的
//
this.FlowLayoutPanel3.SetFlowBreak(this.Button1,真);
this.Button1.Location =新System.Drawing.Point(3,3);
this.Button1.Name =Button1的;
this.Button1.Size =新System.Drawing.Size(75,23);
this.Button1.TabIndex = 0;
this.Button1.Text =Button1的;
this.Button1.UseVisualStyleBackColor = TRUE;
//
//将Button2
//
this.FlowLayoutPanel3.SetFlowBreak(this.Button2,真);
this.Button2.Location =新System.Drawing.Point(3,32);
this.Button2.Name =Button2的;
this.Button2.Size =新System.Drawing.Size(75,23);
this.Button2.TabIndex = 1;
this.Button2.Text =Button2的;
this.Button2.UseVisualStyleBackColor = TRUE;
//
//将Button3
//
this.Button3.Location =新System.Drawing.Point(3,61);
this.Button3.Name =按钮3;
this.Button3.Size =新System.Drawing.Size(75,23);
this.Button3.TabIndex = 2;
this.Button3.Text =按钮3;
this.Button3.UseVisualStyleBackColor = TRUE;
这是一个错误,它已经存在了很长时间。的问题是,对于FlowLayoutPanel的布局引擎计算第一行的宽度错误,其中包括第2控制的宽度,尽管它得到了换到第二行
解决办法是愚蠢的,但有效的,添加一个假面板为0的第一个控制后的宽度。如果你与设计师这样做,那么先删除它并拖动它在正确的地方,到了第一个控制权。那么其保证金设定为(0,0,0,0),大小为(0,0)在属性窗口。
I 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 = new System.Drawing.Point(84, 77);
this.FlowLayoutPanel1.MinimumSize = new System.Drawing.Size(10, 10);
this.FlowLayoutPanel1.Name = "FlowLayoutPanel1";
this.FlowLayoutPanel1.Size = new System.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 = new System.Drawing.Point(127, 3);
this.FlowLayoutPanel3.MinimumSize = new System.Drawing.Size(10, 10);
this.FlowLayoutPanel3.Name = "FlowLayoutPanel3";
this.FlowLayoutPanel3.Size = new System.Drawing.Size(162, 87);
this.FlowLayoutPanel3.TabIndex = 1;
//
//Button1
//
this.FlowLayoutPanel3.SetFlowBreak(this.Button1, true);
this.Button1.Location = new System.Drawing.Point(3, 3);
this.Button1.Name = "Button1";
this.Button1.Size = new System.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 = new System.Drawing.Point(3, 32);
this.Button2.Name = "Button2";
this.Button2.Size = new System.Drawing.Size(75, 23);
this.Button2.TabIndex = 1;
this.Button2.Text = "Button2";
this.Button2.UseVisualStyleBackColor = true;
//
//Button3
//
this.Button3.Location = new System.Drawing.Point(3, 61);
this.Button3.Name = "Button3";
this.Button3.Size = new System.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.
这篇关于如何获得FlowLayoutPanel.AutoSize与FlowBreak工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!