C#:如何在备忘录中添加一行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/760395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C#: How to add a line to a memo?
提问by Ivan Prodanov
I have a RichBox(memo) that I'd like to add lines to.
我有一个 RichBox(memo),我想向其中添加行。
Currently,I use this
目前,我使用这个
RichBox1.text += "the line I'd like to add" + "\n";
Isn't there something like the method in Delphi below?
是不是有类似下面Delphi中的方法的东西?
Memo.Lines.add('The line I''d like to add');
采纳答案by Chris Van Opstal
AppendTextis the closest it gets. Unfortunately you still have to append the newline character:
AppendText是最接近的。不幸的是,您仍然必须附加换行符:
RichBox1.AppendText( "the line I'd like to add" + Environment.NewLine );
回答by JaredPar
You can use the AppendText method from TextBoxBaseand explicitly add the new line
您可以使用 TextBoxBase 中的 AppendText 方法并显式添加新行
RichBox1.AppendText("the line i'd like to add" + Environment.NewLine);
回答by Andrew Garrison
You could use an extension method to add this handy add
method to the RichTextBox class.
http://msdn.microsoft.com/en-us/library/bb383977.aspx
您可以使用扩展方法将此方便的add
方法添加到 RichTextBox 类。
http://msdn.microsoft.com/en-us/library/bb383977.aspx
public static class Extension
{
public static void add(this System.Windows.Forms.RichTextBox richText, string line)
{
richText.Text += line + '\n';
}
}