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