在文本框中添加新行而无需重新填充现有文本C# [英] Adding new line in textbox without repalcing existing text C#

查看:75
本文介绍了在文本框中添加新行而无需重新填充现有文本C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中按下按钮后在文本框中添加新行而不重新排列现有文本?

How to add new line in textbox without repalcing existing text after pressing a button in C# ?

推荐答案

TextBox1.Text += " learn to use Google";




为了添加新行,首先需要将文本框模式设置为MultiLine.这是一个例子.



In order to add new line, first you need to set the textbox mode to MultiLine. Here is an example.

TextBox1.TextMode = TextBoxMode.MultiLine;
TextBox1.Text = "First Line" + Environment.NewLine + "Second Line";
TextBox1.Text += "\nThird Line\r\nFourth Line";



结果看起来像

一线
第二行
第三行
第四行



The results will look like

First Line
Second Line
Third Line
Fourth Line


您可以使用 StringBuilder [ ^ ]类 AppendLine [
You can use StringBuilder[^] class AppendLine[^] functionality. Look the example at the bottom of the article.


这篇关于在文本框中添加新行而无需重新填充现有文本C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆