C# 如何使列表内容在文本框中并排显示
我想在一个文本框中并排显示两个列表的内容 问题是第二个只出现在第一个的下面 下面,红色的内容应位于maxlen列下,而不是Seq列中的数字50下C# 如何使列表内容在文本框中并排显示,c#,wpf,C#,Wpf,我想在一个文本框中并排显示两个列表的内容 问题是第二个只出现在第一个的下面 下面,红色的内容应位于maxlen列下,而不是Seq列中的数字50下 private void button7_Click(object sender, EventArgs e) { textBox1.Text = "Seq MaxLen\r\n"; foreach (object o in MaxLen)
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = "Seq MaxLen\r\n";
foreach (object o in MaxLen)
{
textBox1.Text += String.Join(Environment.NewLine, MaxLen);
}
foreach (object a in SeqIrregularities)
{
textBox1.Text += String.Join(Environment.NewLine, SeqIrregularities);
}
}
编辑:我第一次回答得太快,完全错了 您需要循环浏览这两个列表,并查看是否有值和应用填充(正如Brian建议的)来格式化文本
textBox1.Text = "Seq".PadRight(10) + "MaxLen";
for (int i = 0; i < Math.Max(MaxLen.Count, SeqIrregularities.Count); i++)
{
textBox1.Text += Environment.NewLine;
string text = String.Empty;
if (i < MaxLen.Count)
{
text = MaxLen[i].ToString();
}
text = text.PadRight(10);
if (i < SeqIrregularities.Count)
{
text += SeqIrregularities[i];
}
textBox1.Text += text;
}
textBox1.Text=“Seq”.PadRight(10)+“MaxLen”;
对于(int i=0;i
编辑:第二个“如果”中的输入应该是“如果”,而不是“MaxLen”编辑:我第一次回答得太快,完全错了 您需要循环浏览这两个列表,并查看是否有值和应用填充(正如Brian建议的)来格式化文本
textBox1.Text = "Seq".PadRight(10) + "MaxLen";
for (int i = 0; i < Math.Max(MaxLen.Count, SeqIrregularities.Count); i++)
{
textBox1.Text += Environment.NewLine;
string text = String.Empty;
if (i < MaxLen.Count)
{
text = MaxLen[i].ToString();
}
text = text.PadRight(10);
if (i < SeqIrregularities.Count)
{
text += SeqIrregularities[i];
}
textBox1.Text += text;
}
textBox1.Text=“Seq”.PadRight(10)+“MaxLen”;
对于(int i=0;i
编辑:第二个“如果”中的键入应该是seqruption而不是MaxLen,因此现在,您的
文本框正在删除额外的空白。您需要在文本框中设置xml:space=“preserve”
实际上,我会使用两个文本框
或一个项控件
,因此现在,您的文本框
正在删除多余的空白。您需要在文本框中设置xml:space=“preserve”
实际上,我会使用两个文本框
或一个项控件
,假设这些列表的长度相同(如果没有,则会有点复杂):
string result=“Seq MaxLen\r\n”;
对于(int i=0;i
假设这些列表的长度相同(如果不是,则会有点复杂):
string result=“Seq MaxLen\r\n”;
对于(int i=0;i
看看这是否有帮助:
textBox1.Text = "Seq".PadRight(10) +"\tMaxLen\r\n";
for(int i = 0; i < SeqIrregularities.Count() || i < MaxLen.Count(); i++)
{
string temp = "";
if(i >= SeqIrregularities.Count())
temp = "".PadRight(10) + "\t" + list2[i];
else
if(i >= MaxLen.Count())
temp = SeqIrregularities[i].PadRight(10);
else
temp = SeqIrregularities[i].PadRight(10) + "\t" + MaxLen[i];
textBox1.Text += temp + "\r\n";
}
textBox1.Text=“Seq”.PadRight(10)+“\tMaxLen\r\n”;
对于(int i=0;i=seq.Count())
temp=”“.PadRight(10)+“\t”+列表2[i];
其他的
如果(i>=MaxLen.Count())
温度=1[i]。右侧焊盘(10);
其他的
temp=seq[i].PadRight(10)+“\t”+MaxLen[i];
textBox1.Text+=temp+“\r\n”;
}
这样,即使其他条目为空,也应调整每个条目。查看这是否有帮助:
textBox1.Text = "Seq".PadRight(10) +"\tMaxLen\r\n";
for(int i = 0; i < SeqIrregularities.Count() || i < MaxLen.Count(); i++)
{
string temp = "";
if(i >= SeqIrregularities.Count())
temp = "".PadRight(10) + "\t" + list2[i];
else
if(i >= MaxLen.Count())
temp = SeqIrregularities[i].PadRight(10);
else
temp = SeqIrregularities[i].PadRight(10) + "\t" + MaxLen[i];
textBox1.Text += temp + "\r\n";
}
textBox1.Text=“Seq”.PadRight(10)+“\tMaxLen\r\n”;
对于(int i=0;i=seq.Count())
temp=”“.PadRight(10)+“\t”+列表2[i];
其他的
如果(i>=MaxLen.Count())
温度=1[i]。右侧焊盘(10);
其他的
temp=seq[i].PadRight(10)+“\t”+MaxLen[i];
textBox1.Text+=temp+“\r\n”;
}
这样,即使其他条目是空的,每个条目也应该被调整。
你需要垫文本来让它正确显示。你可以添加一些非破坏性的空间,或者一个标签。为什么你不考虑一个带有列的控件?@ DROPPTABLE用户,我想到了,但是我的代码是如何工作的呢?我是新来的,所以我不太懂语法all@IAbstract布瑞恩请ELABROATE您需要垫文本,以使它正确显示。您可以添加一些非破坏性的空间,或选项卡。为什么不考虑一个带有列的控件?@ DROPPTABLE用户,我想,但这将如何与我的代码一起工作?我是新来的,所以我不太懂语法all@IAbstract和Brian请Elabroates它们的长度不一样:(@user7068,所以只需找出哪一个较短,然后应用上述方法。如果sequnructions
较长,则使用它的其余元素:result+=String.Format(“{0}\r\n”,sequnructions[i].ToString())
否则以:result+=String.Format(“1}\r\n”,MaxLen[i].ToString());
(其中是“”)嘿@artur gzesiak你能把这个回复作为对原始帖子的编辑吗?在评论部分,代码我很难阅读。谢谢!它们的长度不一样:(@user7068所以只要找出哪一个较短,然后应用上面的方法。然后,如果sequnructions
较长,则使用它的其余元素:result+=String.Format(“{0}\r\n”,sequnructions[i].ToString());
other