CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2011
    Posts
    73

    [RESOLVED] How to declare the Sub from the Class?

    I have a HeaderFile MyProject_Datas.h
    //MyProject_Datas.h
    public ref class MyUsefulDatas
    {
    blah...blah...blah...
    public: static System::Void Item_Name( System::Object^ Sender, System::Windows::Forms::KeyEventArgs^ e) {
    blah...blah...blah...
    }
    public: static System::Void Party_Name( System::Object^ Sender, System::Windows::Forms::KeyEventArgs^ e) {
    blah...blah...blah...
    }
    };

    And now from my Form2 - textBox2 I would like to declare

    textBox2->KeyDown += gcnew KeyEventHandler(MyUsefulDatas, &MyUsefulDatas::Party_Name); ????????

    Iam not getting the above line........

    Also I would like to learn same statement, how to use in "delegate" statement like the below.....????

    textBox2->KeyDown += delegate { .....???????? }

    Thanks...

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: How to declare the Sub from the Class?

    You should post in the .NET forum instead. This forum is for native C++.

    Edit: Sorry, the forum should be Managed C++ and C++/CLI
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Dec 2011
    Posts
    73

    Resolved Re: How to declare the Sub from the Class?

    After spending my whole day I found the crazier worth of the word, what is "static" ...

    Also after removing the word "static" from the above declaration it works well..
    Let it be useful to the searchers....

    MyUsefulDatas^ MyUseDta=gcnew MyUsefulDatas;

    textBox2->KeyDown += gcnew KeyEventHandler(MyUseDta, &MyUsefulDatas::Pty_NameCell);


    Thanks...

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: How to declare the Sub from the Class?

    [ Moved thread ]
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How to declare the Sub from the Class?

    Quote Originally Posted by MAHEY View Post
    After spending my whole day I found the crazier worth of the word, what is "static" ...

    Also after removing the word "static" from the above declaration it works well..
    Mainly for the sake of completeness, now that it works, let me note that it is possible to attach static class member functions as event handlers; just the delegate construction syntax is different in this case:

    Code:
    textBox2->KeyDown += gcnew KeyEventHandler(MyUsefulDatas::Pty_NameCell);
    Whether a static event handler actually makes more sense depends on the concrete scenario, of course.

    Let it be useful to the searchers....
    Thanks. Perhaps it would even be a bit more useful with code tags...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Dec 2011
    Posts
    73

    Re: [RESOLVED] How to declare the Sub from the Class?

    Thanks Eric.. I get clear...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured