具有不同显示格式的 Devexpress RegEx 掩码不起作用
Devexpress RegEx Mask with different Displayformat doesn't work
我有一个 Textedit 控件,我希望它以某种方式运行:
当控件有输入焦点时,我想只允许输入正整数(不是零)。我通过使用 Properties.Mask 实现了这一点,效果很好。
当控件没有输入焦点时,我希望它显示输入的数字,但末尾有“,00”。
所以基本上,当我输入内容时,我只会看到我输入的内容,例如“17”但是当控件失去焦点时,我希望它显示“17,00”。所以我只允许输入整数,但控件将始终在后面添加“,00”。
我的理解是基本上有两种不同的"modes":DisplayMode和EditMode。
EditMode = 控件有焦点。
DisplayMode = 控件没有焦点。
在 EditMode 中,我可以将内容输入到我的 Textedit 控件中。能进什么不能进,由Mask决定。
当我失去焦点时,它会进入显示模式。在这里我无法在 TextEdit 中输入任何内容,但现在显示的文本不再由掩码决定,而是由 属性 "Properties.DisplayFormat" 决定。所以为了实现我的目标,我尝试将 DisplayFormat.FormatString 设置为“0.00”,以便它始终显示两位小数 "x,00".
不知何故,这没有按预期工作。 DisplayFormat 似乎没有做任何事情,即使在 DisplayMode 中,TextEdit 仍然只显示没有小数位的整数。
我知道我可以使用事件来解决这个问题,但我认为这就是 DisplayFormat、EditFormat 和 Mask 的用途,我真的不想为那么小的东西处理多个事件。
根据 DevExpress 知识库 topic DisplayFormat
在未绑定模式下不工作。
Problems with formatting occurs because an unbound text editor stores
a value as a string, therefore formatting cannot be applied.
If you use XtraEditors 3 or higher, you may wish to set the editor's
Mask.MaskType property to Numeric. In this case, the editor is forced
to handle the edit value as a number and, therefore, it can format it.
If you wish not to use the Numeric (or DateTime) mask, please use the
ParseEditValue event to convert a string to a number.
我建议您使用 Numeric
掩码和 n0
作为编辑掩码:
要完成上述操作相当简单:
要只允许正整数,您需要将 MaskType 设置为 Numeric
并使用 EditMask ##########;
。 #
的数量代表可能的小部件数量,所以十次 #
意味着您可以使用十位数。 (参见 nempoBu4 的回答)
要在控件失去焦点时显示额外的 ,00
,只需将 DisplayFormat 设置为 FormatType = Numeric
和 FormatString = n2
.
我有一个 Textedit 控件,我希望它以某种方式运行:
当控件有输入焦点时,我想只允许输入正整数(不是零)。我通过使用 Properties.Mask 实现了这一点,效果很好。
当控件没有输入焦点时,我希望它显示输入的数字,但末尾有“,00”。
所以基本上,当我输入内容时,我只会看到我输入的内容,例如“17”但是当控件失去焦点时,我希望它显示“17,00”。所以我只允许输入整数,但控件将始终在后面添加“,00”。
我的理解是基本上有两种不同的"modes":DisplayMode和EditMode。
EditMode = 控件有焦点。
DisplayMode = 控件没有焦点。
在 EditMode 中,我可以将内容输入到我的 Textedit 控件中。能进什么不能进,由Mask决定。
当我失去焦点时,它会进入显示模式。在这里我无法在 TextEdit 中输入任何内容,但现在显示的文本不再由掩码决定,而是由 属性 "Properties.DisplayFormat" 决定。所以为了实现我的目标,我尝试将 DisplayFormat.FormatString 设置为“0.00”,以便它始终显示两位小数 "x,00".
不知何故,这没有按预期工作。 DisplayFormat 似乎没有做任何事情,即使在 DisplayMode 中,TextEdit 仍然只显示没有小数位的整数。
我知道我可以使用事件来解决这个问题,但我认为这就是 DisplayFormat、EditFormat 和 Mask 的用途,我真的不想为那么小的东西处理多个事件。
根据 DevExpress 知识库 topic DisplayFormat
在未绑定模式下不工作。
Problems with formatting occurs because an unbound text editor stores a value as a string, therefore formatting cannot be applied.
If you use XtraEditors 3 or higher, you may wish to set the editor's Mask.MaskType property to Numeric. In this case, the editor is forced to handle the edit value as a number and, therefore, it can format it.
If you wish not to use the Numeric (or DateTime) mask, please use the ParseEditValue event to convert a string to a number.
我建议您使用 Numeric
掩码和 n0
作为编辑掩码:
要完成上述操作相当简单:
要只允许正整数,您需要将 MaskType 设置为 Numeric
并使用 EditMask ##########;
。 #
的数量代表可能的小部件数量,所以十次 #
意味着您可以使用十位数。 (参见 nempoBu4 的回答)
要在控件失去焦点时显示额外的 ,00
,只需将 DisplayFormat 设置为 FormatType = Numeric
和 FormatString = n2
.