C# 如何在富文本框中添加行?

C# 如何在富文本框中添加行?,c#,textbox,richtextbox,C#,Textbox,Richtextbox,我编写了以下代码来创建一个简单的字典应用程序: private void btnDefine_Click(object sender, EventArgs e) { //string word = txtWords.Text; XmlDocument xDoc = new XmlDocument(); try { string [] words = txtWords.Text.Split('\

我编写了以下代码来创建一个简单的字典应用程序:

    private void btnDefine_Click(object sender, EventArgs e)
    {
        //string word = txtWords.Text;
        XmlDocument xDoc = new XmlDocument();
        try
        {
            string [] words = txtWords.Text.Split('\n');
            foreach (string word in words ){
            xDoc.Load("http://www.dictionaryapi.com/api/v1/references/collegiate/xml/" + word + "?key=[KEY]");
            txtWords.Text = (xDoc.SelectSingleNode("entry_list/entry/def/dt").InnerText);

            Clipboard.SetText(txtWords.Text);
            lblCopied.Text = "Copied to the clipboard!";
        }
        }
        catch
        {
            MessageBox.Show("That is not a word in the dictionary, please try again.", "Word not found in the dictionary", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

    }
}
}
此表单包含一个丰富的文本框,您可以在其中输入单词,它将为您定义单词。现在,只要我在文本框中输入一个单词,我就得到了定义。但是,如果我在文本框中输入两个或更多的单词,我会得到列表中最后一个单词的定义,我如何使它以新行显示所有定义。也就是说,如果我在文本框中输入三个单词并按btnDefine,我将在文本框中获得所有这三个单词的定义。

您可以在不同的行上以类似的方式输出定义。看

List<string> definitions = new List<string>();
foreach (string word in words )
{
    xDoc.Load("http://www.dictionaryapi.com/api/v1/references/collegiate/xml/" + word + "?key=[KEY]");
    string definition = (xDoc.SelectSingleNode("entry_list/entry/def/dt").InnerText);
    definitions.Add(definition);
}
txtWords.Text = String.Join("\n", definitions);
Clipboard.SetText(txtWords.Text);
lblCopied.Text = "Copied to the clipboard!";