如何设定控件的输入内容限制? 如果是DevExpress的控件有个Mark属性可以输入正则表达式来限定输入格式的。很好用 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先感谢1楼老兄,正则表达式~我是用VS2005 C#写WinForm private void txtUserID_TextChanged(object sender, EventArgs e) { if (txtUserID.Text.Length > 0) { if (Encoding.Default.GetByteCount (txtUserID.Text) > 20) { int selIndex = txtUserID.SelectionStart; int selLength = txtUserID.SelectionLength; txtUserID.Text = txtUserID.Text.Substring(0, txtUserID.Text.Length - 1); if (selIndex > txtUserID.Text.Length) { selIndex = txtUserID.Text.Length + 1; selLength = 0; } else { if (selLength > txtUserID.Text.Length - selIndex) { selLength = txtUserID.Text.Length - selIndex; } } txtUserID.SelectionStart = selIndex; txtUserID.SelectionLength = selLength; } } }只能想到这样,再具体、苛刻点怎么加工呢? 查了下,确实没用过,介绍也挺简单人性化的,但是Using跟引用是啥没有找到,照搬原样肯定报错。“网上能轻松查到”我也不必跟这里了是吧 有没有办法取到数据库中存储的时间值的毫秒 VS2010 下 c# 程序不能使用皮肤 C# regex 正则表达式 匹配 所有东西 C#在线通讯 局域网内通讯 VS2005 / VS2008 简单实用代码生成器 - LT.VS2005AddIns C#项目实战指导 关于报错的问题 如何把字节数组转成数字 思归请进!!!:) C# winfrom项目,怎么样实现通过WINAPI 关闭对象的句柄窗口后,还能再次获取该句柄窗口 如何实现一个窗体响应多个事件 关于安装程序问题!!!
我是用VS2005 C#写WinForm
private void txtUserID_TextChanged(object sender, EventArgs e)
{
if (txtUserID.Text.Length > 0)
{
if (Encoding.Default.GetByteCount (txtUserID.Text) > 20)
{
int selIndex = txtUserID.SelectionStart;
int selLength = txtUserID.SelectionLength;
txtUserID.Text = txtUserID.Text.Substring(0, txtUserID.Text.Length - 1);
if (selIndex > txtUserID.Text.Length)
{
selIndex = txtUserID.Text.Length + 1;
selLength = 0;
}
else
{
if (selLength > txtUserID.Text.Length - selIndex)
{
selLength = txtUserID.Text.Length - selIndex;
}
}
txtUserID.SelectionStart = selIndex;
txtUserID.SelectionLength = selLength;
}
}
}
只能想到这样,再具体、苛刻点怎么加工呢?