C ++/CLI Winform中的Lambda表达式 [英] Lambda expression in C++/CLI Winform
本文介绍了C ++/CLI Winform中的Lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何在C ++/CLI WinForm中编写以下代码吗?
我搜索了两天,尝试了几次,但没有成功.
Hi,
could somebody tell me how can I write following codes in C++/CLI WinForm?
I''ve searched two days and tried several times, but without success.
private void OnOpenForm2Click(object sender, EventArgs e)
{
var form2Obj = new Form2();
form2Obj.Shown += (o, args) => { btnOpenForm2.Enabled = false; };
form2Obj.FormClosed += (o, args) => { btnOpenForm2.Enabled = true; };
form2Obj.Show();
}
推荐答案
Lambda表达式在C ++ 11中引入:
http://en.wikipedia.org/wiki/C%2B%2B11#Lambda_functions_and_expressions [ ^ ].
更确切地说,您需要的是匿名方法.请参阅:
http://en.wikipedia.org/wiki/Anonymous_function#C.2B.2B [ ^ ].
如果您的C ++/CLI版本足够新,那么您也可以在C ++/CLI上使用它.
另请参阅本文:
使用Lambda:C ++,C#,C ++/CX和. C ++/CLI [ ^ ].
也请参阅我对这个问题的评论.在最坏的情况下,如果只需要显示的功能或代码,则始终可以定义单独的命名函数FormShownHandler(System::Object, System::EventHandler)
和FormClosedHandler(System::Object, System.Windows.Forms::FormClosedEventArgs)
而不是匿名方法.
—SA
Lambda expressions are introduced in C++11:
http://en.wikipedia.org/wiki/C%2B%2B11#Lambda_functions_and_expressions[^].
More exactly, what you need is anonymous methods. Please see:
http://en.wikipedia.org/wiki/Anonymous_function#C.2B.2B[^].
If your version of C++/CLI is new enough, you can use it on C++/CLI as well.
Please see also this article:
Using lambdas - C++ vs. C# vs. C++/CX vs. C++/CLI[^].
And also see my comment to the question. In worst case, if you just want the functionality or the code you show, you can always define separate named functionsFormShownHandler(System::Object, System::EventHandler)
andFormClosedHandler(System::Object, System.Windows.Forms::FormClosedEventArgs)
instead of anonymous methods.
—SA
这篇关于C ++/CLI Winform中的Lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文