Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys. Sorry if my question is too basic, but I haven't found the answer.
I have a VB.NET class which is compiled in a DLL:
VB
Public class PiArc

    Dim m_EnableEvents as Boolean

    Private Sub m_Modified()
        If m_EnableEvents = True Then
            RaiseEvent OnModify()
        End If
    End Sub

    Public Event OnModify()
end class

And I have a C++/CLI class in a different dll, which is derived from the first:
C++
public ref class GfxArc : public Geometry::PiArc{
public:
    GfxArc(){ //constructor
        //ALL I need is to attach a handler the event raised in the (base)object.
    };
    void onRefreshProperty(){
         //REFRESH stuff
    };
};

I need to attach a handler to the event defined in the base class.
In VB.NET it's simple, you just use the Handles keyword to attach an event handler. Is this also possible in C++/CLI? How?
Thank you
Posted

It's fairly straightforward, see this MSDN article:

http://msdn.microsoft.com/en-us/library/ms235237(v=vs.100).aspx[^]

That said, since this is a parent-class - child-class situation, you may also want to look at making it a virtual method in the base class and then overriding it in the derived.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 14-Feb-12 13:01pm    
Correct, a 5.
--SA
C++
public ref class GfxArc : public Geometry::PiArc{
public:
    void onRefreshProperty(){
         //REFRESH stuff
    };

    GfxArc(){ //constructor
        this->OnModify += gcnew Geometry::PiArc::OnModifyEventHandler( this, 
                          &GfxArc::onRefreshProperty );
    }; 
};

When you make an event in VB.NET, an event handler in the background is made (OnModifyEventHandler in this case).
I spent half a day until I found this out.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900