views:

221

answers:

1

Hi !

In C#, I can do (*):

        Button b = new Button();
        b.Click += ButtonOnClick;
    :
    void ButtonOnClick(object sender, RoutedEventArgs e)
    {
        // do something
    }

But in C++/CLI I can't do:

    Button ^ b = gcnew Button();
    b->Click += ButtonOnClick;
:
void ButtonOnClick(Object ^ sender, RoutedEventArgs ^ e)
{
    // do something
}

I get a compiler error complaing about the += ButtonOnClick: 2>.\blub.cpp(108) : error C3867: 'MyListBoxItem::ButtonOnClick': function call missing argument list; use '&MyListBoxItem::ButtonOnClick' to create a pointer to member

(The tip the compiler gives me doesn't work because it isn't a static method.)

What is the equivalent of (*) in C++/CLI ?

Thx Marc

A: 
Alex Reitbort
That gives me: error C2275: 'System::EventHandler' : illegal use of this type as an expression. Looking up MAKE_DELEGATE in msdn leads me to MFC Library Reference.But I guess, I have to create a (.net) Delegate somehow - but I don't know how.
marc40000
Oh, while that also doesn't work, it pointed me int he right direction. This is working:b->Click += gcnew RoutedEventHandler(this, Thx :) - What shouldI mark as answer now?
marc40000