Winforms 将文本框格式化为货币
我是 Winforms 开发的新手,我将在文本框中向用户显示数据。文本框将与货币数据进行数据绑定,因此我尝试格式化正在显示的值。
我查看了一个蒙版文本框,但这并不是我正在寻找的,因为它没有将分放在小数点后。
我需要为每个文本框编写与此类似的代码吗?
TextBox.Text = DataSet.DataView[0].Amount.ToString("c");
我有很多文本框需要格式化,所以我想知道是否需要为每个文本框执行此操作。有人有什么建议吗?
I am new to Winforms development and I going to be displaying data to my users in a textbox. The textbox will be databound with data that is currency so I am trying to Format the value that is being displayed.
I looked at a Masked Text Box but that isn't exactly what I am looking for because it doesn't put the cents after the decimal.
Do I need to code for each textbox similar to this?
TextBox.Text = DataSet.DataView[0].Amount.ToString("c");
I have alot of textboxes that need to be formatted so I am wondering if I need to do this for each one. Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建自己的从标准文本框派生的文本框
用法:
You can create your own TextBox derived from standard one
Usage:
假设您有来自双变量(例如
mySumInvestment
)的总计,并且您希望将其放置在美国货币格式的文本框中。那么这就是你可以做的事情Imagine you have the total coming from a double variable such as
mySumInvestment
and you want to place it a textbox with US Currency Format. Then this is something you could do