C# 如何取消委托
可能的重复:
取消订阅 C# 中的匿名方法
我有一些面板,在创建时它们被委托为可点击的:
int z2 = z;
PicBx[z].Click += delegate { clicked(z2, null); };
如果程序需要的话,我希望能够删除它。我尝试使用:
int z2 = z;
PicBx[z].Click -= delegate { clicked(z2, null); };
但没有成功。有什么办法可以从中删除可点击的委托吗?
Possible Duplicate:
Unsubscribe anonymous method in C#
I have some Panels that when created they are delegated to become clickable:
int z2 = z;
PicBx[z].Click += delegate { clicked(z2, null); };
I want to be able to remove this if the program calls for it. I tried using:
int z2 = z;
PicBx[z].Click -= delegate { clicked(z2, null); };
But it didn't work. Is there any way to remove the clickable delegation from it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法取消订阅匿名委托,您需要保留对委托的引用
或创建命名函数
希望这有帮助
You can't unsubscribe from anonymous delegate, you need to keep reference to delegate
Or create named function
Hope this helps