Click here to Skip to main content
12,511,920 members (52,160 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++/CLI event
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:
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:
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 14-Feb-12 6:43am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
SAKryukov 14-Feb-12 13:01pm
   
Correct, a 5.
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 15 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100