我如何格式的值作为货币(例如123,456.50)在文本框中打字时? [英] How can I format a value as money (ex. 123,456.50) in a textbox while typing?

查看:140
本文介绍了我如何格式的值作为货币(例如123,456.50)在文本框中打字时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打字时格式化我的文本框的内容。 我知道我可以在引发LostFocus 事件做到这一点,但我想,当我键入它做。有没有人对如何落实这有什么建议?

I want to format the contents of my textbox while typing. I know that I can do this in LostFocus event, but I want it to be done while I am typing. Does anyone have any suggestions on how to implement this?

推荐答案

而不是试图操纵这件事你自己,考虑使用专门用来处理格式化输入控制。 具体而言,您需要 MaskedTextBox中 控制,这是现有的文本框,使您可以设置使用的有效和无效的输入区分一个面具的增强版。用户甚至得到视觉反馈,因为他们的类型。

Rather than trying to rig this up yourself, consider using a control that's specifically designed to handle formatted input. Specifically, you need the MaskedTextBox control, which is an enhanced version of the existing textbox that allows you to set a "mask" used to distinguish between valid and invalid input. The user even gets visual feedback as they type.

您需要设置 面膜属性告诉你怎么想它的内容的控制被格式化。所有可能的值示链接文档中。要显示的钱,你会使用类似: $ 999,999.00 ,从而重新$ P $ 0到999999整洁的部分范围psents货币价值的货币,千分之一,和十进制字符将被自动替换在运行时与他们的文化特定的等价,使之更容易编写国际软件。

You'll need to set the Mask property to tell the control how you want its contents to be formatted. All of the possible values are shown in the linked documentation. To display money, you would use something like: $999,999.00, which represents a currency value in the range of 0 to 999999. The neat part is that the currency, thousandth, and decimal characters are automatically replaced at run-time with their culture-specific equivalents, making it much easier to write international software.

这篇关于我如何格式的值作为货币(例如123,456.50)在文本框中打字时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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