遮罩的texbox [英] masked texbox

查看:76
本文介绍了遮罩的texbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的程序中有一个带遮罩的文本框,用于插入资金.
如何将这个被屏蔽的文本框求和到另一个文本框?我想将金额添加到用户添加的金额中.

Hi,

I have a masked textbox in my program to insert money.
How to sum this masked textbox to another textBox? I want sum to the money where the user added it.

推荐答案

将文本框的文本值转换为十进制
convert your text value of text box to decimal


更改Mask 属性-请参见此处 [ ^ ].
Change the Mask property - see here[^].


//You first convert into int or long. Well You are saying its money so better use float or double data types.
//here is the code. I prefer double.
if (maskedTextBox1.Text != null)//Cheak if textbox has value or not. If value present then convert it to double.
{
  double money=Convert.ToDouble(maskedTextBox1.Text)+Convert.ToDouble(maskedTextBox1.Text);//converted into double data type. money is variable.
textBox1.Text=money.ToString();//.ToString() method is available for any varable, any function, any data type to convert it into string for displating in textbox or some thing.
}


转换两个值并添加它们.尝试一下.
为什么要加倍并浮动.因为钱是十进制格式.例如100.80


Convert the two values and add them thats it. Try it it works.
WHy double and float. Beacause money is in decimal format. for example 100.80


这篇关于遮罩的texbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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