如何在 Visual Studio C# 中将值放入 TextBox 中,而不删除 TextBox 上已有的信息

发布于 2025-01-17 08:05:52 字数 70 浏览 2 评论 0原文

textBox1.Text = "4 块金块"; 如果我想再次按下它,它不会将其作为列表,而是会替换它。我该如何解决这个问题?

textBox1.Text = "4 Nuggets";
If i wanted to press that again it wont put it as a list instead it will replace it. How do i fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我要还你自由 2025-01-24 08:05:52

如果您想首先像列表一样编写,则应该将文本框设置为多行。
您可以通过设计器或在运行时使用代码来制作它。如果你没有的话,就在互联网上写了 make textbox multiline 。

因此,如果您有一个像这样

=>4 Nuggets 的

文本框,并且您想添加另一行,例如

=>4 Nugget

=>2 Chicken,

就像注释中一样,您应该使用 +=,但要传递下一行,您应该使用 '\n'

所以你的代码必须是这样的。

    string newLine = //something;
    textBox1.Text += "'\n'" + newLine;

或者

     string newLine = //something;
     textBox1.Text = textBox1.Text + "'\n'" + 
     newLine;

如果您需要进一步的帮助,请写下

If you want to write like a list first you should make your textbox multiline.
You may make it from the designer or with code at runtime. Just wrote make textbox multiline to the internet if you did not.

So if you have a textBox like this

=>4 Nuggets

and you want to add another line like

=>4 Nugget

=>2 Chicken

as like in the comments you should use +=, but to pass the next line you should use '\n'

So your code must be something like this.

    string newLine = //something;
    textBox1.Text += "'\n'" + newLine;

Or

     string newLine = //something;
     textBox1.Text = textBox1.Text + "'\n'" + 
     newLine;

If you need further assistance just wrote

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文