仅为包含电话号码的文本框显示数字小键盘

编程入门 行业动态 更新时间:2024-10-17 07:29:12
本文介绍了仅为包含电话号码的文本框显示数字小键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个文本框,它只能包含数字。与添加新联系人时的电话号码文本框类似。以编程方式,我们如何只打开数字键盘而不是文本/数字键盘。 这样用户就无法随时输入文本。虽然可以在以后对符号进行验证。 您是否可以提供一个代码片段,仅用于打开数字小键盘,仅为文本框输入数字。

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 | 行号

更多推荐

仅为包含电话号码的文本框显示数字小键盘

本文发布于:2023-11-24 23:22:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小键盘   仅为   文本框   电话号码   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!