gpt4 book ai didi

c++ - 在 .Net C++ 中将 EventHandler 转换为 MouseEventHandler?

转载 作者:行者123 更新时间:2023-11-28 03:32:12 25 4
gpt4 key购买 nike

我在尝试将 EventHandler 转换为 MouseEventHandler 时遇到了一些问题。

System::EventHandler^ method = gcnew System::EventHandler(this, &MainForm::Exit_Action);
if (e->trigger == "onmousedown") {
c->MouseDown += (MouseEventHandler^)(method); // error

(这是指一个 System::Windows::Forms::Form 类)

有没有办法做到这一点?

最佳答案

嗯,EventHandler 不是 MouseEventHandler(它们甚至不在同一个继承层次结构中),所以这不应该工作。

为什么不在 if 中创建一个新的(嗯,gcnew)MouseEventHandler?很便宜:)

(在 C# 中,您通常使用 c.MouseDown += Exit_Action; 之类的东西创建隐式 lambda,但我不知道 C++/CLI 中是否有类似的语法。)

关于c++ - 在 .Net C++ 中将 EventHandler 转换为 MouseEventHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12218569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com