将片段从C#转换为C ++ / CLI [英] Tranlating a snippet from C# to C++/CLI
本文介绍了将片段从C#转换为C ++ / CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将此代码段从c#转换为C ++ / CLI,但我甚至不确定它是什么:
I want to translate this snippet to C++/CLI from c#, but I'm not even sure what it is:
private PrintDocument document = new PrintDocument();
document.PrintPage += new PrintPageEventHandler(PrintPage);
到目前为止,这是我所做的,但我想我需要另一个参数:
So far this is what I've made of it, but I think I need another parameter:
PrintDocument^ m_document;
m_document->PrintPage += gcnew PrintPageEventHandler(PrintPage);
推荐答案
我将在编译的基础上尝试这个 - 证明将在运行时出现!< br $>
I'm going try this on the basis that it compiles - the proof will come at run time!
m_document->PrintPage += gcnew PrintPageEventHandler(this, PrintPage);
这只是声明一个名为'document'的变量,类型为PrintDocument,并使用默认构造函数初始化它。
然后它为其PrintPage事件设置一个事件处理程序,该事件是指向应该在类中某处声明的PrintPage()方法的委托。
如何不幸的是,我不知道在C ++ / CLI中将事件连接到委托方法。抱歉。我不确定您是否遇到C#或C ++ / CLI部分的问题。
This just declares a variable named 'document' of type PrintDocument, and initializes it with default constructor.
Then it sets up an event handler for its PrintPage event, which is a delegate pointing to a PrintPage() method that should be declared somewhere in the class.
How to wire up an event to a delegate method in C++/CLI is out of my knowledge, unfortunately. Sorry. I was not sure if you had problems with the C# or the C++/CLI part.
更改
Change
PrintDocument^ m_document;
m_document->PrintPage += gcnew PrintPageEventHandler(PrintPage);
to
to
PrintDocument^ m_document;
m_document->PrintPage += gcnew PrintPageEventHandler(&PrintPage);
这篇关于将片段从C#转换为C ++ / CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文