我正在写使用C#。我使用下面的代码到我的文本转换为数字文本框在Win形式的桌面应用程序:避免重复的代码在C#
private void txtPrice_KeyPress(object sender, KeyPressEventArgs e)
{
//if (!char.IsControl(e.KeyChar)
// && !char.IsDigit(e.KeyChar)
// && e.KeyChar != '.')
// {
// e.Handled = true;
// }
if(!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
是蚂蚁设计模式或技术来存储上面的代码只有一次,并且不写它,每次在窗体中的每个文本框?
如果您在一个表单上,只需将多个TextBox控件上的KeyPress事件设置为txtPrice_KeyPress。 – FodderZone