从单个文本框中添加多个数字以获得总数 [英] adding multiple numbers from a single text box to get a total

查看:92
本文介绍了从单个文本框中添加多个数字以获得总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用1x文本框,1x标签,1x按钮制作一个简单的表单。我希望能够在文本框30中添加一个数字,然后单击按钮,然后在文本框中添加另一个数字  50 然后单击按钮,然后在文本框中添加另一个数字
  3并在标签中添加总数会有83.是否有可能在视觉工作室用字符串做?     

Hi guys, I am trying to make a simple form with a 1x textbox, 1x label, 1x button. I would like to be able to put a number in the textbox 30 and click the button then add another number in textbox 50 and click the button then add another number in textbox 3 and in the label, the total would be there 83. Is it possible to do it in visual studio with a string?     

推荐答案

我认为这是可能的。在C#中,按钮的
单击事件处理程序为:

string text_from_textbox = . . .;
string text_from_label = . . .;
int a, b;

int.TryParse( text_from_label, out a );
if( int.TryParse( text_from_textbox, out b ) )
{
   string new_text_for_label = ( a + b ).ToString();
   // set label's text
   // . . .
}


这篇关于从单个文本框中添加多个数字以获得总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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