感谢您使用微软产品。在C#中,可以在TextBox1控件的KeyPress事件句柄中监控KeyPressEventArgs的KeyChar属性值,如果符合要求,则设置其Handled属性为False,反之设置其Handled属性为True。
如下提供一段示例代码,供您参考:
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(Char.IsDigit(e.KeyChar) || e.KeyChar.ToString() =="." || e.KeyChar == 8)
{
//Indicate the System.Windows.Forms.Control.KeyPress event is not handled
e.Handled = false;
}
else
{
e.Handled = true;
}
}— 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
如下提供一段示例代码,供您参考:
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(Char.IsDigit(e.KeyChar) || e.KeyChar.ToString() =="." || e.KeyChar == 8)
{
//Indicate the System.Windows.Forms.Control.KeyPress event is not handled
e.Handled = false;
}
else
{
e.Handled = true;
}
}— 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
解决方案 »
- 各位大虾,晚上好,在线等急~!谁有C# .net Email 的发送代码,给小弟参考下,谢谢
- 手机怎么支持.NET
- 求一个正则表达式,关于怎么取javascript中的Hyperlink
- 绑定后的一个怪问题!已经折磨了我半天!
- 高手帮我看看是那错了
- 排列组合的问题!比较简单
- C#多核编程
- ========100分请教一个让我困惑的问题:在MainMenu的触发ItemMenu事件的问题。========
- 请问C#怎样用钩子?
- google被黑了,快去看啊!变成爱应四谈的方程了!
- 怎么这么多人在叫没分,我来送点分。前5名1-3个三角的有效,5000分陆续有来。以后不能常来回答问题了,留个好尾!
- 问:
第二个问题你可以对这个文本框得KeyPress事件进行检查,如果用户输入了回车键,则你就把焦点移到指定得文本框去