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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:13:34+00:00 2026-06-04T02:13:34+00:00

if there is another question that explains this I apologize for not being able

  • 0

if there is another question that explains this I apologize for not being able to find it, but I think it might have to do with my unfamiliarity with some of the terms involved with what I’m trying to do.

What I’m trying to do is to add an eventhandler to a button by name. So for example, in the code below instead of knowing that I want to add showInfo, can I reference the EventHandler by name (string) like “showInfo”?

myButton.Click += new EventHandler(showInfo);

void showInfo(object sender, EventArgs e)
{
    // ..
}
  • 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-04T02:13:35+00:00Added an answer on June 4, 2026 at 2:13 am

    You can create a delegate from a method via reflection, and then subscribe that to the event via reflection, yes. Sample code:

    using System;
    using System.Reflection;
    
    class Publisher
    {
        public event EventHandler Foo;
    
        public void RaiseFoo()
        {
            EventHandler handler = Foo;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
    }
    
    class Subscriber
    {
        public void HandleEvent(object sender, EventArgs e)
        {
            Console.WriteLine("In HandleEvent");
        }
    }
    
    class Test
    {
        static void Main()
        {
            var subscriber = new Subscriber();
            var publisher = new Publisher();
    
            var methodInfo = typeof(Subscriber).GetMethod("HandleEvent");
            var handler = (EventHandler) Delegate.CreateDelegate(
                   typeof(EventHandler), subscriber, methodInfo);
    
            var eventInfo = typeof(Publisher).GetEvent("Foo");
            eventInfo.AddEventHandler(publisher, handler);
    
            publisher.RaiseFoo();
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this was asked somewhere in another question, but the wording used there
In answering another persons question here on SO, I discovered that there is a
There's another question: howto make diff look like svn diff? but I want the
This is related to another open question of mine . While there aren't any
Probably a stupid question, but is there a Javascript method to browse another url,
I appreciate that this may appear to many as a dum question but I
This is not so much a technical question but still part of the development
I'm not sure if I've even labelled this question properly. But what I'm trying
Right, another question on queries (there must be a syntax guide more helpful than
Is there another way to do this Query ? $query = SELECT * FROM

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.