2016-11-14 33 views
0

我設置了這個flowLayoutPanel,裏面的控件排列好了,直到最後到達面板的下邊框,然後控件開始排列右邊(形成另一個列)保持垂直流。我只想要一列。爲什麼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; 
+0

,因爲它可以。它的工作是不浪費空間並避免顯示滾動條。考慮使其寬度減少。 –

回答

2

使用

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);