如何控制textbox的输入类型?

therealseas 2005-06-15 01:03:36
比如想控制用户输入日期类型或数字类型,该如何实现啊?
...全文
189 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
TonyZeus 2005-06-15
  • 打赏
  • 举报
回复
不大理解意思,不过好像KeyPress之类也可以吧
StreamH 2005-06-15
  • 打赏
  • 举报
回复
控制textbox的输入类型有意义么?
fuyiyong 2005-06-15
  • 打赏
  • 举报
回复
同意楼上的 !!
xyy2 2005-06-15
  • 打赏
  • 举报
回复
用异常处理来控制,如要求texeBox1.Text只能输入整数,则用如下程序来操作:


try
int num = Convert.ToInt32( texeBox1.Text ); //输入整数能正常运行,否则转入出错处理部分
catch
{
输入非整数时的处理;
}
wang8712 2005-06-15
  • 打赏
  • 举报
回复
你可以用正则表达式:
你可以参考一下这个例子,主要是多了解正则表达式:
using System;
using System.Text.RegularExpressions;

namespace Samples {
public class RegExMatcher {
public static void Main(String[] args){
Regex digitregex = new Regex("(?<digit>[0-9])");
String before = "Here is so4848me te88xt with emb4493edded numbers.";

if ( args.Length > 0 ) {
before = String.Join(" ", args);
}

String after = digitregex.Replace(before, "");

System.Console.WriteLine("替换之前:" + before);
System.Console.WriteLine("替换之后:" + after);

System.Console.WriteLine();
System.Console.WriteLine("按 Enter 键继续...");
System.Console.ReadLine();
}
}
}

therealseas 2005-06-15
  • 打赏
  • 举报
回复
这个控件哪有啊?
du9232 2005-06-15
  • 打赏
  • 举报
回复
CompareValidator 控件

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧