我该如何分配事件处理程序在C ++ / CLI的事件? [英] How do I assign an event handler to an event in C++/CLI?

查看:244
本文介绍了我该如何分配事件处理程序在C ++ / CLI的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加事件来一个事件/委派?什么是语法? 它是在C ++ / CLI和C#一样的吗?

How do I add "events" to an "event"/delegate? What is the syntax? Is it the same in C++/CLI and in C#?

推荐答案

在的 C#,你的 + = 运营商做到这一点:

In c#, you do it with the += operator:

someObj.SomeEvent += new EventHandler(Blah_SomeEvent);

...

private void Blah_SomeEvent(object sender, EventArgs e)
{
}

更比一岁以后修改

它已经因为我张贴了这个答案,有人注意到我,也许这是错的很长一段时间。我真的不知道为什么OP标志着我作为右一个答案(或许OP一直在寻找这个,而不是的 C ++ - ?CLI 语法现在谁知道)

More-than-a-year-later-edit

It has been a long time since I posted this answer and someone noticed me that maybe it was wrong. I really don't know why the OP marked my answer as the right one (maybe OP was looking for this rather than c++-cli syntax? Who knows now).

不管怎样,在的 C ++ - CLI 的将是:

Anyway, in c++-cli it would be:

someObj->SomeEvent+= gcnew EventHandler(this, &Blah_SomeEvent);

这篇关于我该如何分配事件处理程序在C ++ / CLI的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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