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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:42:32+00:00 2026-06-12T12:42:32+00:00

At the moment I am in the process of building a custom button handler

  • 0

At the moment I am in the process of building a custom button handler (I needed to integrate the kinect into the button system which also used a mouse) then I got to a horrible thing called Event Handling.. at least an hour yelling at my pc :P. I was wondering, before I go and spend a while changing my system to allow for my new want, which is to have multiple events per handler, I was wondering, is the way I'm going to try work (I would just try, but I'm getting off for the night, so my hope is that I can save some time when I boot the computer up tomorrow and not attempt if my system isn't designed for it)

Also, ive seen a getInvoc list or somthing like that before when I was coding.. Would I add multiple delegates onto it then get that list and itterate over it?

On previous examples I had seen where people used:

public event EventHandler myEventHandler;

I had to use:

private Dictionary<BtnEvent, Delegate> m_events;

and then they did the following to add a handler (their way, not mine):

myObj.myEventHandler += delegate(object sender, EventArgs ea)
{
     //do stuff on event
};

first.. If they ran this twice, once with funcA and second with funcb would it run both? or just one?

second, if I applied that logic of += to a Delegate would it work? (I had to use Delegate as I was storing the handlers inside of a dictionary, this allowed for logical access to handlers through use of an enum)

(my code)

private Dictionary<BtnEvent, Delegate> m_events;

//....

m_events = new Dictionary<BtnEvent, Delegate>(6);
m_events.Add(BtnEvent.CLICK_ENTER,  null);
m_events.Add(BtnEvent.CLICK_LEAVE,  null);
m_events.Add(BtnEvent.CLICK_STAY,   null);
m_events.Add(BtnEvent.HOVER_ENTER,  null);
m_events.Add(BtnEvent.HOVER_LEAVE,  null);
m_events.Add(BtnEvent.HOVER_STAY,   null);

//....

public bool addHandle(BtnEvent stateToGet, Delegate function)
{
    bool success = false;

    if(m_events.ContainsKey(stateToGet))
    {
        m_events[stateToGet] = function;
    }

    return(success);
}

// CHANGE ABOVE TO:

public bool addHandle(BtnEvent stateToGet, Delegate function)
{
    bool success = false;

    if(m_events.ContainsKey(stateToGet))
    {
        m_events[stateToGet] += function;
    }

    return(success);
}

Will changing m_events[stateToGet] = function; to m_events[stateToGet] += function; allow me to have multiple event handles (functions I passed to addHandle) be called through the following code?

private void ExecuteEvent(BtnEvent currEvent)
{
    if(m_events.ContainsKey(currEvent))
    {
        if(m_events[currEvent] != null)
        {
           m_events[currEvent].DynamicInvoke(null);
        }
    }
}
  • 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-06-12T12:42:33+00:00Added an answer on June 12, 2026 at 12:42 pm

    Please see below code which answers your first question:

    public partial class Form1 : Form
        {    
            public Form1()
            {
                InitializeComponent();
                this.Load += new EventHandler(Form1_Load);
            }
    
            void Form1_Load(object sender, EventArgs e)
            {
                funcA();
                funcB();
            }
    
            private void funcA()
            {
                button1.Click += new EventHandler(button1_Click);
            }
    
            private void funcB()
            {
                button1.Click += new EventHandler(button1_Click);
            }
    
            void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("I am in event handler");
            }
    
        }
    

    On clicking the Button, “I am in event handler” message is shown twice which means += operator works in similar way with delegates as it works with integers or strings. It simply adds the function handler to the queue and upon execution of events, calls all the function pointers in queue.

    Regarding your second question, I think you wont achieve the expected behavior by changing = to +=. What I understand from your statement is that, you wish to execute multiple events handlers like CLICK_ENTER, CLICK_LEAVE on calling ExecuteEvent() function. However, since you are storing event handlers and their delegates in a Dictionary, changing = to += will only work in the same way as illustrated in above code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a process at the moment which iterates through files in
I'm currently in the process of building an embedded system, using an ARM Cortex
I am in the process of building a Rails app that will hook into
I'm a little frustrated at the moment with the custom delegate process in objective-c.
I am in the process of building interactive front-ends to a distributed application which
I am trying to automate a process which at the moment is done by
I'm working on a project at the moment that involves building a system in
So a OS multi-tasks and runs one process at a given moment (assuming it's
At the moment I'm trying to figure out how use default and custom settings
I'm building a website at the moment, I've some html fragment that is being

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.