Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:52:57+00:00 2026-05-25T22:52:57+00:00

say I have three classes: class1, control1 and form1; form1 instantiate contorl. and control1

  • 0

say I have three classes: class1, control1 and form1; form1 instantiate contorl. and control1 instantiate class1, the later produces some event that I need to ‘bypass’ to form1, to achieve that I have made an intermediate function as shown below:

public delegate void TestHandler(String^ str);
public ref Class class1
{
    event TestHandler^ TestHappen;
    void someFunction()
    {
        TestHappen("test string");
    }
};

public ref Class control1
{
    event TestHandler^ TestHappen;
    class1^ class1Obj;
    control1()
    {
        class1Obj= gcnew class1();
        class1Obj->TestHappen+= gcnew TestHandler(this,&control1::onTest);  
    }   
    void onTest(String^ str)
    {
        TestHappen(str);
    }
};

public ref Class form1
{
    control1^ control1Obj;
    form1()
    {
        control1Obj= gcenw control1();
        control1Obj->TestHappen+= gcnew TestHandler(this,&form1::onTest);
    }
    void onTest(String^ str)
    {
        //do something with the string...
    }
};

I don’t want to use class1 in form1, are there a way to remove the intermediate onTest() function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:52:58+00:00Added an answer on May 25, 2026 at 10:52 pm

    Yes, if you use a custom event, you can write its add-handler and remove-handler functions so that they add and remove the delegate directly from another object’s event.

    For example:

    public ref class control1 // in "ref class", class is lowercase!
    {
        class1 class1Obj; // stack-semantics syntax, locks class1Obj lifetime to be same as the containing control1 instance
    
    public:
        event TestHandler^ TestHappen {
            void add(TestHandler^ handler) { class1Obj.TestHappen += handler; }
            void remove(TestHandler^ handler) { class1Obj.TestHappen -= handler; }
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have three separate color schemes that are used on various pages in
Let's say you have three tables named Item, Event, and Seat, constructed as such:
I'm planning to try contours on some image. Lets say I have three object
Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
Lets just say that I have three textboxes: TextBox1, TextBox2, TextBox3. Normally if I
Let's say I have three classes A, B and C. B extends A C
Let's say I have three classes set up as follows: abstract Class A {
Lets say I have three django model classes - lets call them A, B
Lets say we have this interface: interface IVehicle { ... } And some classes
Let's say I have three classes, example.ClassA, example.ClassB, and example.ClassLoader. ClassA prints out HelloWorld

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.