简体   繁体   English

将多行文本添加到具有不同按钮的文本框 c#

[英]Add multiple rows of text to a text box with different buttons c#

I have built an interface full of buttons (47) and each of them have an address.我构建了一个充满按钮的界面(47 个),每个按钮都有一个地址。 When you click the button, it's supposed to put the address in the text box.当您单击按钮时,它应该将地址放入文本框中。 I can do this, but only with one address at a time.我可以这样做,但一次只能使用一个地址。 When I push a different button the previous address gets copied over by the new one.当我按下一个不同的按钮时,以前的地址会被新的地址复制过来。

The code behind the buttons are simple:按钮背后的代码很简单:

protected void btnYmca_Click(object sender, EventArgs e)
{
    txtOut.Text = "Some address here\n";
}

All of these buttons are set up like this.所有这些按钮都是这样设置的。 There is nothing in these buttons to clear the text, but it does automatically when I click a different button.这些按钮中没有任何内容可以清除文本,但是当我单击不同的按钮时它会自动清除。 The text box is set to MultiLine.文本框设置为 MultiLine。

Is there a way to make the text line stay in the text box when you hit one button, then add a new address on a line below it?当您点击一个按钮时,有没有办法让文本行留在文本框中,然后在它下面的一行中添加一个新地址? I have a separate button to clear the text box when finished.我有一个单独的按钮来完成后清除文本框。

You need to add a + before the = .您需要在=之前添加一个+ This will then append the value instead of overwriting it.然后,这将附加该值而不是覆盖它。

protected void btnYmca_Click(object sender, EventArgs e)
{
    txtOut.Text += "Some address here\n";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#富文本框,添加字符串,输出到其他文本框 - C# Rich text box , add string, output to different textbox C#文本框,不同的类,backgroundWorker - c# text box, different class, backgroundWorker 如何在C#中读取多个文本框 - how read multiple text box in C# 从数据库获取多个值,并在索引更改C#时显示在组合框和不同的文本框中 - get multiple values form the database and show in combo box and different text boxes when the index change c# 如何在Windows窗体中添加多个文本框的值。 C#,Visual Studios - How do I add values of multiple text box in windows forms. C#, Visual Studios C#如何将不同按钮的按钮文本设置为同一文本框 - C# How to set button text of different buttons to the same textbox 富文本框中的多个超链接到多个页面C# - Multiple Hyperlinks to Multiple Pages in rich text box c# c# 如何将按钮添加到数组并设置所有按钮的文本 - c# how to add Button to array and set text of all buttons 如何动态创建文本框和按钮并从c#中的每个文本框中获取值? - How to create text boxes and buttons dynamically and get the value from each text box in c#? c#在组合框中着色具有不同文本的单个框 - c# coloring individual box in combobox that have different text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM