C#多行Texbox [英] C# Multiline Texbox

查看:92
本文介绍了C#多行Texbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用一个新的C#.Net程序寻求帮助.我将单选按钮和列表框的参数传递给只读的多行文本框.数据传输工作正常,但是,一个选择会覆盖另一个选择,我希望它可以在多行"文本框中的换行"上显示单独选择的值.我已经看过"\ n \ r",但看起来好像新值将始终覆盖先前选择的值.

任何帮助将不胜感激

问候

埃本

ebenowen"@" aol.com

解决方案

我建​​议购买一些有关C#的书,并阅读以涵盖这些基础知识.切勿使用\ n \ r,而应使用可移植的Environment.NewLine.如果设置属性,则更改其值.

tb.Text ="1" + Environment.NewLine;
tb.Text ="2" + Environment.NewLine; ;这将用2代替1
tb.Text = tb.Text +"1" + Environment.NewLine; ;这将添加文本末尾.


除了Christian的正确答案外,还可以使用+ =

TextBox1.Text += Environment.NewLine;

来连接字符串.您还可以使用string.Format 如果要串联很多字符串,则可以使用 StringBuilder [ ^ ]类


我很确定"\ r \ n"是正确的组合(而不是"\ n \ r"),尽管您应该使用Environment.NewLine.试试这个:

 textBox1.AppendText(Environment.NewLine + " ); 


另外,下次再输入一些代码,我们也许可以为您提供更好的帮助.


Hi,
I seek some assistance please with a new C#.Net program I''m playing with. I am passing arguments from radio buttons and Listbox''s into a Multi line textbox which is read only. The transfer of data works fine, however, one selection overwrites the other and I''d like it to display the individually selected values on a NewLine within the Multiline text box. I have looked at the "\n\r" but it appears as if the new value will always overwrite the previously selected value.

any help will be appreciated

regards

Eben

ebenowen"@"aol.com

解决方案

I''d recommend buying some books on C# and reading them to cover these sort of basics. NEVER use \n\r, use Environment.NewLine, which is portable. If you set a property, you change it''s value.

tb.Text = "1" + Environment.NewLine;
tb.Text = "2" + Environment.NewLine; ; this will REPLACE the 1 with the 2
tb.Text = tb.Text + "1" + Environment.NewLine; ; This ADDS the text on the end.


in addition to Christian''s correct answer, strings can also be concatenated by using +=

TextBox1.Text += Environment.NewLine;

You can also use string.Format

TextBox1.Text = string.Format("{0}{1}", TextBox1.Text, Environment.NewLine);

If you''re concatenating a lot of strings, you can use the StringBuilder[^] class too.


I''m pretty sure "\r\n" is the correct combination (not "\n\r"), although you should use Environment.NewLine. Try this:

textBox1.AppendText(Environment.NewLine + "New Line");


Also, next time put some code and we may be able to help you better.


这篇关于C#多行Texbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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