为什么flowlayoutPanel水平扩展

本文关键字:扩展 水平 flowlayoutPanel 为什么 | 更新日期: 2023-09-27 18:17:44

我已经设置了这个flowLayoutPanel,里面的控件安排得很好,直到最后到达面板的底部边界,然后控件开始安排在右侧(形成另一列)保持垂直流。我只需要一列。

this.panel.Anchor = 
((System.Windows.Forms.AnchorStyles)
(((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)| System.Windows.Forms.AnchorStyles.Right)));
this.panel.AutoScroll = true;
this.panel.BorderStyle = BorderStyle.None;          
this.panel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.panel.Location = new System.Drawing.Point(0, 184);
this.panel.Name = "myPanel";
this.panel.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.panel.Size = new System.Drawing.Size(300, 371);
this.panel.TabIndex = 9;

为什么flowlayoutPanel水平扩展

使用

this.panel.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight;

不是

this.panel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;

如果您只想要一个列,请在您的应用程序中添加以下代码,就在控件添加到您的flowlayoutpanel

this.panel.SetFlowBreak(<<YOUR_ADDED_CONTROL_NAME>>, true);

例子
Button btn1 = new Button();
btn1.Text = "TEST";
btn1.Height = 30;
btn1.Width = 100;
this.panel.Controls.Add(btn1);
this.panel.SetFlowBreak(btn1, true);