我在 winforms 中有一个 flowlayout 控件,我已将其流向设置为 TopDown 但它一直从左到右添加控件,autoscroll 也设置为 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);
最佳答案
将flowLayoutPanel1
的WrapContents
属性设置为false
,否则将不允许在右侧移动那些控件合身。为了能够滚动剪辑的内容,您可以将 AutoScroll
属性设置为 true
代码如下:
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.WrapContents = false;
flowLayoutPanel1.AutoScroll = true;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.Controls.Add(listBoxNewInput);
关于c# - flowlayout 控件不断在 winforms 中以错误的方向添加控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7741392/