无法将类型'bool'隐式转换为'System.EventHandler' [英] Cannot implicitly convert type 'bool' to 'System.EventHandler'

查看:528
本文介绍了无法将类型'bool'隐式转换为'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 a boolean value is assigned instead of an Event handler. For example, the Click event of a Button can be handled by assigning the Event 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆