gpt4 book ai didi

c# - 在 C# 中更改多行文本框的特定行

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:48 24 4
gpt4 key购买 nike

我无法更改多行文本框的特定字符串。

假设多行文本框的第一行是 "Hello" & 第二行是 "Bye"。但是当我尝试像下面这样更改第二行的值时。

textBox1.Lines[1] = "再见";

当我使用 Debug 模式看到结果时,它不是“再见”。

我也读过这个MSDN文章与此 stackoverflow问题却得不到想要的答案。

最佳答案

如 MSDN 所述(您提供的链接):

By default, the collection of lines is a read-only copy of the lines in the TextBox. To get a writable collection of lines, use code similar to the following: textBox1.Lines = new string[] { "abcd" };

因此,您必须“获取”Lines 集合,更改它,然后返回到TextBox。可以这样实现:

var lines = TextBox1.Lines;
lines[1] = "GoodBye";
TextBox1.Lines = lines;

或者,您可以替换文本,例如 Wolle suggested

关于c# - 在 C# 中更改多行文本框的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44112453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com