Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI Events
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 at 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
0 OriginalGriff 468
1 Sergey Alexandrovich Kryukov 305
2 PhilLenoir 115
3 RajeeshMenoth 110
4 Peter Leow 100
0 Sergey Alexandrovich Kryukov 6,465
1 OriginalGriff 5,926
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,540


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 15 Feb 2012
Copyright © CodeProject, 1999-2014
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