将序列号粘贴到多个文本字段上
在我的应用程序中,用户可以使用 32 个字符的序列号升级他们的产品(从试用版到完整版)。
为了使其对我的(付费)客户尽可能友好,我希望能够复制并粘贴序列号。
我希望我的客户将光标放在许可证下的第一个字段中,当用户粘贴 32 个字符的许可证时,我希望它填充所有字段。
我不知道从哪里开始,所以如果你能指出我正确的方向,那就太好了。
In my application users can upgrade their product (from trial to full) using a 32 characters serialnumber.
To make it as user friendly as possible for my (paying) customers I would like to be able to copy and paste the serial.
I want my customers to place the cursor in the first field under license and when the user pastes the 32 chars license I want it to fill all the fields.
I don't know where to start so if you can point me in the right direction that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在第一个文本框中,我会设置一个很大的限制。
在“文本已更改”上,检查长度。如果变化大于 4(您的最大值)。删除多余的内容并将其分布在文本框中。
如果你复制粘贴,它会将文本更改为 32,并且它会起作用。您还可以更改光标(我认为它是 .Focus() 但我可能是错的),以便它自动在框之间“跳跃”。
In the first textbox, I would put a large limit.
On the 'text changed', check the length. If the change is greater than 4 (your maximum). Delete the extra stuff and spread it over your textboxes.
If you copy-paste, it'll text change of 32, and it would work. You could also change the cursor (I think its .Focus() but I could be wrong) so it automatically 'hops' between the boxes.
您只需连接到第一个文本框的文本更改事件,然后修剪和修剪即可。将粘贴的文本分成 4 组,并设置其他文本框的文本。
非常简单,并且应该“正常工作”。
You could just hook up into the text changed event of the first textbox, and trim & split the pasted text into, groups of 4, and set the text of the other textboxes.
Pretty straightforward, and should "just work".
您可以重写 WndProc 以捕获粘贴事件(Windows 消息)。然后只需将粘贴的文本复制到文本框中即可。完整示例,很大程度上受到这个答案的启发:
You can override WndProc to capture the paste event (Windows message). Then simply take the pasted text, and copy into the textboxes. Full example, heavily inspired by this answer: