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 1104601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:30:25+00:00 2026-05-17T01:30:25+00:00

I have a sample form with 3 windows. Each window has a label and

  • 0

I have a sample form with 3 windows. Each window has a label and the main form has a button.

I have a class with the following code:

    public class CustomEventArgs : EventArgs
{
    public string Message { get; set; }
    public CustomEventArgs(string message)
    {
        Message = message;
    }
}

public delegate void CustomEventHandler(object sender, CustomEventArgs args);

public class EventCode
{
    public void Process()
    {
        var cea = new CustomEventArgs("I was processed");
        if (MyEvent != null)
        {
            MyEvent.Invoke(this, cea);
        }
    }

    public event CustomEventHandler MyEvent;
}

On my main form, I am going to push the button and have it process code in my EventCode class, and then invoke the event. I want the event to send a message to both forms that are open, which will then display a message on the screen.

Here is my button click code in Form1:

        private void Form1_Load(object sender, EventArgs e)
    {
        Window1 w1 = new Window1();
        w1.Show();

        Window2 w2 = new Window2();
        w2.Show();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        EventCode ec = new EventCode();
        ec.Process();
    }

In Window 1:

EventCode ec = new EventCode();
    public Window1()
    {
        InitializeComponent();
        ec.MyEvent += new CustomEventHandler(ec_MyEvent);
    }

    void ec_MyEvent(object sender, CustomEventArgs args)
    {
        label1.Text = args.Message;
    }

Repeated for Window 2

When I click on the button, the event subscription does not display the text on each of the forms. If i create an event subscription on the main form, it will display.

I am not sure which route to take to make this functionality to work.

Thoughts?

  • 1 1 Answer
  • 1 View
  • 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-17T01:30:25+00:00Added an answer on May 17, 2026 at 1:30 am

    Subscriptions to events only work for the instances you subscribe on. If you create a new instance of EventCode and subscribe to the events, the event will only be raised if you call Process on that specific instance.

    Quick solution: pass the EventCode instance you create in the main window to the two child windows.

    public Window1(EventCode eventCode)
    {
        InitializeComponent();
        eventCode.MyEvent += new CustomEventHandler(ec_MyEvent);
    }
    
    void ec_MyEvent(object sender, CustomEventArgs args)
    {
        label1.Text = args.Message;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I have created sample windows application for learning to implement localization. My each
I have a windows form application that uses a Shared class to house all
I have the following var storage = [], obj; $('form input[type=hidden]').each(function(){ obj = {};
I have a simple multiple question form, each question has 4 answers and users
I have a simple Windows Form that hosts property controls at runtime. When the
I have ListBox called lstProductGroups. On a simple Windows Form, a method called GetGroups
I would like to have a window with a simple form (radio buttons and
I have a script.I will show sample. <form> <textarea id='input'></textarea> <input onclick=convert() value=go function
I have a VERY simple windows form that the user uses to manage Stores.
In my windows forms project I have a parent form that is creates other

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.