如何在文本框中将删除的字符替换为0 [英] How to replace deleted character with 0 in the textbox

查看:136
本文介绍了如何在文本框中将删除的字符替换为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WinForms,如何与零替换删除的字符。例如,12.45是在文本框中。如果小数点后删除,它应该成为12.00。同样的方式,如果删除了前面,000.45。和默认值应为000.00。

In winforms, how to replace deleted character with zero. for example 12.45 is in the textbox. if we delete after decimal point, it should become 12.00. same way if deleted in the front, 000.45. and default value should be 000.00.

推荐答案

使用的 MaskedTextBox中和设置的面膜属性 0.00 PromptChar 属性 0 - 这应该给你的行为接近你在找什么。

Use a MaskedTextBox and set the Mask property to 0.00 and PromptChar property to 0 - this should give you behaviour close to what you are looking for.

但是,比如轻微的怪癖,如果你的价值是 3.22 你删除 3 其他数字将转移到左侧,因此该值将成为 2.20 ,而你可能会希望值更改为 0.22

However, there is a slight quirk for example if your value was 3.22 and you deleted 3 the other numbers would shift to the left, so the value would become 2.20 whereas you would probably expect the value to change to 0.22.

我认为,如果你想要那种控制的,你需要通过处理按键事件来实现一些自定义的控制。

I think if you wanted that sort of control you would need to implement something custom by handling the key press events on the control.

这篇关于如何在文本框中将删除的字符替换为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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