C# winform 怎样给textBox1一行一行地增加数据?

lcmlhs_2005 2010-09-30 04:55:42
如题:我想给temBox1一行一行地增加数据,怎么弄?textBox1.Lines[2] = "aaa";这样为什么不行?????、
...全文
3541 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
RLMLover 2010-09-30
  • 打赏
  • 举报
回复
3楼正解
hejialin666 2010-09-30
  • 打赏
  • 举报
回复
textBox1.AppendText("\r\n" + strText);
textBox1.AppendText(strText + "\r\n");
兔子-顾问 2010-09-30
  • 打赏
  • 举报
回复
所以,只能是
string[] lines = textBox1.Lines;
lines[2] = "aaa";
textBox1.Lines = lines;
兔子-顾问 2010-09-30
  • 打赏
  • 举报
回复
[Localizable(true), SRDescription("TextBoxLinesDescr"), Editor("System.Windows.Forms.Design.StringArrayEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MergableProperty(false), SRCategory("CatAppearance")]
public string[] Lines
{
get
{
int num2;
string text = this.Text;
ArrayList list = new ArrayList();
for (int i = 0; i < text.Length; i = num2)
{
num2 = i;
while (num2 < text.Length)
{
char ch = text[num2];
if ((ch == '\r') || (ch == '\n'))
{
break;
}
num2++;
}
string str2 = text.Substring(i, num2 - i);
list.Add(str2);
if ((num2 < text.Length) && (text[num2] == '\r'))
{
num2++;
}
if ((num2 < text.Length) && (text[num2] == '\n'))
{
num2++;
}
}
if ((text.Length > 0) && ((text[text.Length - 1] == '\r') || (text[text.Length - 1] == '\n')))
{
list.Add("");
}
return (string[]) list.ToArray(typeof(string));
}
set
{
if ((value != null) && (value.Length > 0))
{
StringBuilder builder = new StringBuilder(value[0]);
for (int i = 1; i < value.Length; i++)
{
builder.Append("\r\n");
builder.Append(value[i]);
}
this.Text = builder.ToString();
}
else
{
this.Text = "";
}
}
}


看看Lines的定义。
pcable 2010-09-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 symbol_bc 的回复:]

C# code

//首先,应设textbox可多行显示Multiline = true;
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Text = "1111\r\n2222\r\n";
}
[/Quote]

应该 this.textBox1.Text += "1111\r\n2222\r\n";吧
xsi640 2010-09-30
  • 打赏
  • 举报
回复
lines是数组不能直接操作

//将textbox1.lines转成集合
List<string> lists = this.textBox1.Lines.ToList<string>();
//添加一行
lists.Add("asdadaadad");

this.textBox1.Lines = lists.ToArray();
symbol_bc 2010-09-30
  • 打赏
  • 举报
回复

//首先,应设textbox可多行显示Multiline = true;
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Text = "1111\r\n2222\r\n";
}

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧