【发布时间】:2018-03-17 06:06:22
【问题描述】:
这里使用了一个 sn-p 代码,因此文本框(“TxtInput1”)中只有一个小数,并且只有数字:
private void TxtInput1_TextChanged(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
但它给了我以下错误:
CS0123 'TxtInput1_TextChanged' 没有重载匹配委托 '事件处理程序'
我点击了错误,它弹出了这个:
form1.TxtInput1.Location = new System.Drawing.Point(92, 111);
form1.TxtInput1.Name = "TxtInput1";
form1.TxtInput1.Size = new System.Drawing.Size(43, 20);
form1.TxtInput1.TabIndex = 8;
form1.TxtInput1.TextChanged += new System.EventHandler(form1.TxtInput1_TextChanged);
System.EventHandler(form1.TxtInput1_TextChanged); 行带有红色下划线,表示错误。有解决这个问题的办法吗?
【问题讨论】:
-
阅读有关 TextBox.TextChanged 的文档
-
您可以使用 Visual Studio 为您生成事件处理程序。这类似于印刷错误的问题
标签: c# winforms syntax-error