在textChange事件上添加多个文本框文本 [英] Add The Multiple Textbox Text on the textChange Event

查看:95
本文介绍了在textChange事件上添加多个文本框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想添加多个文本框文本,然后在文本已更改"事件上添加文本,如果我删除了这些文本,则这些文本将从总数中减去
喜欢
在我的代码中,我按5,所以结果5
然后我按0,然后结果是55,数字是50
再次按1,结果是556,数字是501
因此,请对此提供帮助
在Advance中致谢

Hi I want to Add multiple textbox text add on text Changed event and if i delete those text so these subtract from the total
Like
in My Code i press 5 so result 5
and after that i press 0 then result is 55 and number is 50
and again i press 1 the result is 556 and number is 501
so pls help on this
Thanks in Advance

推荐答案

当您获得Changed事件时,请阅读以下文本:
When you get the Changed event, read the text:
private void tbNumberEntry_TextChanged(object sender, EventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb != null)
        {
        string numbersEntered = tb.Text;
        ...
        }
    }


然后处理输入文本中的每个字符:


Then process each character in the entered text:

foreach (char c in numbersEntered)
    {
    ...
    }


并将其转换为int并添加到总数中.


And convert it to int and add to the total.

total += (int) char.GetNumericValue(c);
sb.Append(total.ToString());


您将需要定义一个int total和一个StringBuilder sb
然后只需将标签的值设置为以下值:


You will need to define a int total, and a StringBuilder sb
Then just set the value of your label with the value:

labTotal.Text = sb.ToString();


这篇关于在textChange事件上添加多个文本框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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