本文介绍了仅为包含电话号码的文本框显示数字小键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,它只能包含数字。与添加新联系人时的电话号码文本框类似。以编程方式,我们如何只打开数字键盘而不是文本/数字键盘。 这样用户就无法随时输入文本。虽然可以在以后对符号进行验证。 您是否可以提供一个代码片段,仅用于打开数字小键盘,仅为文本框输入数字。
I have a text box and it can contain only numbers. Similar to a phone number text box while adding a new contact. Programatically how can we open only the numeric keypad instead of both text/numeric keypad. By this the user cannot enter text at anytime. Though validation for symbols can be made later. Can you provide a code snippet for opening only a numeric keypad to enter numbers only for the text box.
推荐答案这与你打开的键盘无关。 文本框有一个.KeyPress事件。 你为该事件编写一个方法(一个处理程序) )检查刚刚按下的键是否为数字。如果它是一个数字你允许它。如果它不是,你就把它扔掉。 这很常见,我肯定谷歌的C#数字文本框将为您提供十几个示例。 This has nothing to do with what keypad you open. The textbox has a .KeyPress event. You write a method for that event (a handler) that checks if the key just pressed was a number or not. If it was a number you allow it. If it wasn''t, you throw it away. This is VERY common and I''m sure a Google for "C# numeric textbox" will get you a dozen examples.
如果您想让它旋转一下,还有一个制作自己的屏幕数字键盘的教程。 这个收银机教程就是这样做的:它是一个虚拟数字键盘。 There is also a tutorial for making your own on-screen numeric keypad if you want to give it a whirl. This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard.
输入数字的验证已经完成如下: The validation of entering numbers is already done as: 展开 | 选择 | Wrap | 行号
更多推荐
仅为包含电话号码的文本框显示数字小键盘
发布评论