如何将 TEditMask 格式设置为自动插入空格并在粘贴的文本中使用空格?
给定 TMaskEdit 控件的 EditMask 属性的文本,
>AAAAA_AAAAA_AAAAA_AAAAA_AAAAA_AAAAA_A;0;_
当用户键入时,会自动插入一个空格每 5 个字符之后。
但是,如果用户粘贴已包含空格的文本(例如,从我们发送给他们的电子邮件中复制的文本),则每个空格都会占用所需字符之一,并且文本的最后 5 个字符将丢失。
有没有办法识别 TEditMask 中的特定字符,使其为空或特定字符(在本例中为空格)?或者我可以使用不同的控件吗?
Given this text for the EditMask property of a TMaskEdit control,
>AAAAA_AAAAA_AAAAA_AAAAA_AAAAA_AAAAA_A;0;_
When the user types, a space is automatically inserted after every 5 characters.
However, if the user pastes in text that already contains the spaces (for example, copied from an email we sent them), then each space uses up one of the required characters and the last 5 characters of the text are lost.
Is there a way to identify a particular character in the TEditMask so it is either empty or the specific character (in this case, a space)? Or is there a different control I could use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
TMaskEdit
及其可怕的光学和限制。由于您要操作的文本相当短,您可以直接使用TEdit
并对其文本的更改做出反应:另外,不要错误地为每个文本块使用多个
TEdit
,因为这会扰乱任何想要一次粘贴长序列(?)的剪贴板内容的人 - 我已经看到软件安装这样做总是很痛苦。有一个空表单,添加一个
TEdit
并将其设为OnChange
事件:在 D7 上成功测试:
只删除单个字符感觉很奇怪,
并且当最后一个字符是空格时不起作用。我会把它留给你让它变得完美。Don't use
TMaskEdit
and its horrible optics and limitations. Since the text you want to operate on is rather short you can use aTEdit
directly and react upon changes to its text:Also don't make the mistake to use several
TEdit
s for each block of text, as that will disrupt anyone who wants to paste the clipboard content of the long serial(?) at once - I've seen software installations doing this and it was always a pain.Have an empty form, add a
TEdit
and make this itsOnChange
event:Successfully tested on D7:
Deleting only single characters feels weird, tho,
and does not work when the last one is a space. I'll leave it to you to make it perfect.