Adding strings to a RichTextBox in C#

别等时光非礼了梦想. 提交于 2019-12-19 04:14:32

问题


I currently have a function that will set a value to a RichTextBox, although how could you "add" a value or a new line to it, rather than overwriting existing data in the RichTextBox?

richTextBox2.Text = DateTime.Today + " Hello";

回答1:


richTextBox2.AppendText(Environment.NewLine + DateTime.Today + " Hello"); 



回答2:


richTextBox2.AppendText(String.Format("{0} the date is {1}{2}", "Hello", DateTime.Today, Environment.NewLine));

Please don't use +




回答3:


richTextBox2.Document.Blocks.Clear();
richTextBox2.Document.Blocks.Add(new Paragraph(new Run("string")));



回答4:


richTextBox2.Text = "Something " + richTextBox2.Text + " and something"


来源:https://stackoverflow.com/questions/6485156/adding-strings-to-a-richtextbox-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!