gpt4 book ai didi

c# - FlowLayoutPanel 中的新行

转载 作者:太空宇宙 更新时间:2023-11-03 21:02:01 24 4
gpt4 key购买 nike

我正在使用以下代码在 FlowLayoutPanel 中动态生成控件(win 表单 - c#)。我想在内部 foreach 完成后添加换行符。var fullText = textBox1.Text;

        List<string> listPoints = fullText.Split('#').ToList();

foreach (var listPoint in listPoints)
{
if (listPoint.Contains('^'))
{
var listTextboxes = listPoint.Split('^');
int textBoxCount = listTextboxes.Count();
int index = 1;
foreach (var listTextbox in listTextboxes)
{
CheckBox ck = new CheckBox();
ck.Text = listTextbox;
ck.AutoSize = true;
ck.CheckStateChanged += new EventHandler(this.CheckBox_CheckedChanged);
flowLayoutPanel1.Controls.Add(ck);

if (index < textBoxCount)
{
TextBox tb = new TextBox();
tb.AutoSize = true;
tb.TextChanged += new EventHandler(this.TextBox_TextChanged);
flowLayoutPanel1.Controls.Add(tb);
}
index++;
}

// code for New line break
}
else
{
CheckBox ck = new CheckBox();
ck.Text = listPoint;
ck.AutoSize = true;
ck.CheckStateChanged += new EventHandler(this.CheckBox_CheckedChanged);
flowLayoutPanel1.Controls.Add(ck);

flowLayoutPanel1.
}

最佳答案

使用 SetFlowBreak 方法:

Control lastControl = null;
if (listPoint.Contains('^')) {
var listTextboxes = listPoint.Split('^');
int textBoxCount = listTextboxes.Count();
int index = 1;
foreach (var listTextbox in listTextboxes) {
CheckBox ck = new CheckBox();
ck.Text = listTextbox;
ck.AutoSize = true;
ck.CheckStateChanged += new EventHandler(this.CheckBox_CheckedChanged);
flowLayoutPanel1.Controls.Add(ck);

if (index < textBoxCount) {
TextBox tb = new TextBox();
tb.AutoSize = true;
tb.TextChanged += new EventHandler(this.TextBox_TextChanged);
flowLayoutPanel1.Controls.Add(tb);
lastControl = tb;
} else {
lastControl = ck;
}
index++;
}
if (lastControl != null) {
flowLayoutPanel1.SetFlowBreak(lastControl, true);
}

关于c# - FlowLayoutPanel 中的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44637096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com