开发者

How to add a click handler to a WPF Button in C++/CLR?

开发者 https://www.devze.com 2022-12-10 03:37 出处:网络
In C#, I can do (*): Button b = new Button(); b.Click += ButtonOnClick; : void ButtonOnClick(object sender, RoutedEventArgs e)

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 开发者_Go百科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


try

 b->Click += MAKE_DELEGATE( System::EventHandler, ButtonOnClick );

b->Click += gcnew System::EventHandler(this, &ButtonOnClick);
0

精彩评论

暂无评论...
验证码 换一张
取 消