感谢您使用微软产品。在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))。