通过按下按钮1按文本框2的值... [英] 2 value by a textbox by pressing button1...

查看:63
本文介绍了通过按下按钮1按文本框2的值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用消息框输出一些值...

示例:textbox1输入值"abc"...我按下了按钮1并保留它。当我在textbox1上输入第二个值"cba"并按下按钮1时它将具有2个值...当我按下按钮2时,消息框将显示"abc"。和
第二个值"cba"。

我怎么能这样做...

i am trying to output some values with message box...
example: textbox1 entered value "abc"...and i pressed the button1 and keep it. when i enter the second value "cba"on textbox1 and pressed the button1 it'll be have 2 value...when i press button2 message box will show up "abc" and second value "cba".
how could i do this...

推荐答案

你可以您的表单中有一个字段可以使用
列表< T> 在这里,每按一次按钮,在集合中添加一个新项目,然后在消息框中显示它们。

You can have a field in your form to which would be a collection, let's say you can use List<T> here, and every time button is pressed add a new item in the collection and then show them in Message Box.

代码如下所示:

private List<string> inputs = new List<string>();


protected void Button1_Clicked(object sender,EventArgs args)
{
  // add textbox value in the collection
  inputs.Add(textBox1.Text);
  // show up all values
  Message.Show(String.Join(Environment.NewLine,inputs));

}

以上是最简单的版本,你也可以检查项目是否已经在集合中,跳过它而不是再次添加到避免重复,你也可以检查文本框是否包含空字符串,以及不添加或显示验证
消息它是空的。

The above is the simplest version, you can also check if the item is already in the collection, skip it instead of adding again to avoid duplicates, and you can also check if textbox contains empty string in that case as well don't add or show validation messaged that it is empty.

希望它有所帮助!


这篇关于通过按下按钮1按文本框2的值...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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