c# - flowlayout 控件不断在 winforms 中以错误的方向添加控件

标签 c# winforms user-controls dynamic-controls flowlayoutpanel

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

最佳答案

flowLayoutPanel1WrapContents属性设置为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/

相关文章:

c# - 加载记录集,一次加载 4 个项目

c# - Winforms checkedlistbox勾选一项

.net - 正确处理/关闭用户控件

vb.net - 带像素化的图像缩放

c# - 隐藏 DateTimePicker 的文本和 Usercontrol 调整大小

WPF:ItemsControl 数据模板作为用户控件的问题

c# - 来自代码隐藏的 Api POST

c# - 相当于 foreach 的 XAML

vba - Excel-VBA : Getting the values from Form Controls

c# - 在 StackPanel 中为子级设置动画 - WPF (C#)