14

我在winforms中有一个flowlayout控件,我已将其流向设置为TopDown,但它不断从左到右添加控件,自动滚动也设置为true。

flowLayoutPanel1.Controls.Clear();    
Label labelInput = new Label();
ListBox listBoxNewInput = new ListBox();

//Initialize label's property
labelInput.Text = " #" + Convert.ToInt32(sequence);
labelInput.AutoSize = true;

//Initialize textBoxes Property
listBoxNewInput.HorizontalScrollbar = false;

listBoxNewInput.Items.Add(efforts);
//Add the newly created text box to the list of input text boxes
inputTextBoxesList.Add(listBoxNewInput);

//Add the labels and text box to the form
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(listBoxNewInput);
4

1 回答 1

29

将 的WrapContents属性设置flowLayoutPanel1false,如果这些控件不适合,则不允许将它们移动到右侧。为了能够滚动剪辑的内容,您可以将AutoScroll属性设置为true

这是代码:

flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.WrapContents = false;
flowLayoutPanel1.AutoScroll = true;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.Controls.Add(listBoxNewInput);
于 2011-10-12T14:28:24.430 回答