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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:52:03+00:00 2026-05-27T06:52:03+00:00

How can I register to event and do some actions at runtime? For example

  • 0

How can I register to event and do some actions at runtime?

For example when the user click on a button I want to register to OnMyEvent and run MyFunc that let’s say initialize some textBox with the OnMyEvent args.

I’m using winforms and .NET 4.

EDIT

Maybe I was unclear… I need the ability to register to existing event and add a new method that will run when the event will fire. All at runtime.

EDIT2
i’ll try to give an example…
lets say that i have a class named “A” that have many events OnDataRecived OnDataSend etc…
when the application running the user can choose form a combobox event name to register (i got the events list via reflection because they not constracts, they are generated from xml file) and which data to update when the choosed event is fired.

so for the example the user choose to register to the OnDataReceived and he choose to update property named DataStream. some code…

in run time upon user choosing:

A.OnDataReceived += (s,e) => MyRunTimeMethod(s,e);

private void MyRunTimeMethod(object sender, EventArgs e)  
{
   DataStream = e.Data.Value
}
  • 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-27T06:52:04+00:00Added an answer on May 27, 2026 at 6:52 am

    You are asking how to create a method dynamically at runtime – once you have a reference to that method in a delegate, the question of how to register it to an event is trivial.

    MSDN describes how to do this with MSIL instructions. I doubt that’s what you’re looking for, but it is an option.

    The C# FAQ blog has a much more interesting solution using expression trees. I suppose this is the one you were referring to by originally tagging your post with expression-tree.

    But I would reconsider using dynamic methods at all. How exactly is the user going to specify what action to perform on the event of his choice? I suspect that the options are limited enough that you can get by with something simpler:

    protected void btnRegister_Click(object sender, EventArgs e) {
        switch (cmbEvents.SelectedText) {
            case "OnLoad":
                MyControl.OnLoad += (s, e) => SomeSelectedControl.Text = SomeInputControl.Text;
                break;
    
            //... other cases
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I want to trigger an event (pausing/unpausing some media) whenever the user presses
I need to create registration form for an event. Each person that register can
I have a jQuery plugin that needs to register a click event handler: $.fn.myPlugin
I want to build a web application where users can register and have a
How can I create a form that requires anonymous viewers to register in order
Such a simple question but if I want to add run some code in
In a windows forms application you can register event handlers like this: this.KeyDown +=
I have user control A, and user control B. How can I register an
Im trying to register an event listener for a successful login, so that I
using register_shutdown_function I can register code to execute at the end of a PHP

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.