private void button6_Click(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
}
我有RichTextBox
:
private void richTextBox4_TextChanged(object sender, EventArgs e)
{
}
如何将方法中的数据返回/输出到RichTextBox
?
答案 0 :(得分:2)
获得文件名后,可以使用Enumerable.Aggregate将它们转换为字符串,并将该字符串设置为富文本框的文本:
private void button6_Click(object sender, EventArgs e)
{
richTextBox4.Text =
Directory.GetFiles(@"C:\MyDir\")
.Aggregate("", (text, pathName) =>
text += String.Format("{0}\n", pathName))
);
}
答案 1 :(得分:1)
foreach(string path in filePaths) {
richTextBox4.AppendText(path + Environment.NewLine);
}
答案 2 :(得分:0)
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
richTextBox4.Text = string.Join(Environment.NewLine, filePaths);