无法将类型'bool'隐式转换为'System.EventHandler' [英] Cannot implicitly convert type 'bool' to 'System.EventHandler'
问题描述
无法将类型"bool"隐式转换为"System.EventHandler".
Cannot implicitly convert type ''bool'' to ''System.EventHandler''
推荐答案
分配了boolean
值而不是Event handler
.例如,可以通过将Event handler button1_Click
分配为此处的解释器来处理Button
的Click
事件
http://msdn.microsoft.com/en-us/library/dfty2w4e (v = vs.80).aspx [
The error message stated in the title of the question is displayed if aboolean
value is assigned instead of anEvent handler
. For example, theClick
event of aButton
can be handled by assigning theEvent handler button1_Click
as explainere here
http://msdn.microsoft.com/en-us/library/dfty2w4e(v=vs.80).aspx[^]
button1.Click += new EventHandler(button1_Click);
其中button1_Click
声明如下
where button1_Click
is declared as below
private void button1_Click(object sender, System.EventArgs e)
{
// Add event handler code here.
}
在上面的代码中,如果分配了布尔值,例如
In the above code if a boolean value is assigned like
button1.Click += variableOfBoolValue;
其中variableOfBoolValue
是包含boolean
值的变量,则将引发上述错误.为避免该错误,请分配与要处理的event
相对应的适当类型的Event handler
.
我认为可以通过问题中提供的最少信息来推断出这一点.
where variableOfBoolValue
is a variable containing a boolean
value, then the above error is thrown. To avoid that error assign a Event handler
of appropriate type corresponding to the event
which is to be handled.
I think this is what can be inferred with the minimum info provided in the question.
这篇关于无法将类型'bool'隐式转换为'System.EventHandler'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!