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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:52:38+00:00 2026-05-13T08:52:38+00:00

Simple situation(VS2005, .NET2): I have a textBox1 on a panel1. I need to track

  • 0

Simple situation(VS2005, .NET2): I have a textBox1 on a panel1. I need to track all the emitted events from this textBox1.

Actually, when I need to track a single event(TextChanged, by e.g.) from this textBox1 I add a handler to the (TextChanged event) I set then a non-blocking breackpoint that writes on the output console a message containing the function (eventhandler) name.
So, for a single event I can write this handler and set the breackpoint, but can I do something similar for all possible textbox(or other control)’s events?

alt text http://lh5.ggpht.com/_1TPOP7DzY1E/S0H5NHjXSjI/AAAAAAAAC24/tV0IiUsxwAU/s800/eventsTrack.png

More deeply, I need to know what event have place in a certain moment on the mentioned control (textBox).

Thanks.

  • 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-13T08:52:38+00:00Added an answer on May 13, 2026 at 8:52 am

    Aviad’s post is a good start. You can use it for events of type EventHandler. For other delegate types you can use the same technique creating handler for each type manually.

    If you want to be more flexible you should create event handler in runtime using System.Reflection.Emit. Here is a detailed explanation: http://msdn.microsoft.com/en-us/library/ms228976.aspx. Scroll down to “To generate an event handler at run time by using a dynamic method” title.

    //EDIT

    I created simple class which is able to handle all events of particular object and pass them to universal event handler. Code is based on examples from Microsoft and XTreme.NET Talk.

    Basic idea

    • create method in runtime which has the same arguments as event
    • set this mehod as event handler for each event in Type.GetEvents()
    • from this method call universal event handler

    Usage

    Object to attach to is passed in constructor. Next anonymous method of type UniversalEventHandler is used to handle all events. This method receives event name as eventName and event arguments in args. You can set breakpoint on this method and inspect arguments in Visual Studio or print them by yourself. In this sample usage only event name is printed and can be found in Output window (menu View > Output in Visual Studio). In this example standard button button1 is examined.

    private void Form1_Load(object sender, EventArgs e)
    {            
        UniversalEventHandler handler = (UniversalEventHandler) delegate(string eventName, object[] args)
        {
            System.Diagnostics.Trace.WriteLine(eventName);
        };
    
        EventInspector inspector = new EventInspector(button1, handler);
    
    }
    

    Code

    public delegate void UniversalEventHandler(string eventName, object[] args);
    
    public class EventInspector
    {
        private UniversalEventHandler eventHandler;
        private object srcObject;
    
        public EventInspector(object srcObject, UniversalEventHandler eventHandler)
        {
            this.eventHandler = eventHandler;
            this.srcObject = srcObject;
            Attach();
        }
    
        public void EventReceived(string eventName, object[] args)
        {
            if (eventHandler != null)
                eventHandler(eventName, args);
        }
    
        public void Attach()
        {
            Type type = srcObject.GetType();
            EventInfo[] srcEvents = type.GetEvents();
    
            for (int i = 0; i < srcEvents.Length; i++)
            {
                EventInfo srcEvent = srcEvents[i];
    
                Type[] parameterTypes = GetDelegateParams(srcEvent.EventHandlerType);
                DynamicMethod handler = new DynamicMethod("", typeof(void), parameterTypes, typeof(EventInspector));
                string name = srcEvent.Name;
                ILGenerator il = handler.GetILGenerator();
                il.DeclareLocal(typeof(object[]));
                il.DeclareLocal(typeof(string));
    
                il.Emit(OpCodes.Ldstr, srcEvent.Name);
                il.Emit(OpCodes.Stloc_1);
                il.Emit(OpCodes.Ldc_I4, parameterTypes.Length - 1);
                il.Emit(OpCodes.Newarr, typeof(object));
                il.Emit(OpCodes.Stloc_0);
    
                for (int j = 0; j < parameterTypes.Length - 1; j++)
                {
                    Type parameter = parameterTypes[j];
                    il.Emit(OpCodes.Ldloc_0);
                    il.Emit(OpCodes.Ldc_I4, j);
                    il.Emit(OpCodes.Ldarg, j + 1);
                    il.Emit(OpCodes.Stelem_Ref);
                }
    
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldloc_1);
                il.Emit(OpCodes.Ldloc_0);
    
                MethodInfo eventReceivedMethod = this.GetType().GetMethod("EventReceived", BindingFlags.Public | BindingFlags.Instance);
                il.EmitCall(OpCodes.Callvirt, eventReceivedMethod, null);
                il.Emit(System.Reflection.Emit.OpCodes.Ret);                                 
    
                srcEvent.AddEventHandler(srcObject, handler.CreateDelegate(srcEvent.EventHandlerType, this));
            }
        }
    
        private Type[] GetDelegateParams(Type d)
        {
            MethodInfo delegateMethod = d.GetMethod("Invoke");
            ParameterInfo[] delegateParams = delegateMethod.GetParameters();
    
            Type[] result = new Type[delegateParams.Length + 1];
            result[0] = this.GetType();
    
            for (int i = 0; i < delegateParams.Length; i++)
            {
                result[i + 1] = delegateParams[i].ParameterType;
            }
    
            return result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I have a simple XML document that contains image information. I need to
All, my situation is that I have the basic route, plus some other simple
I have very simple situation and really don't have a clue why this isn't
I have a simple situation (.NET2): a texbox1 on a UserControl1(or Form1). I want
I have this simple situation: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(CascadeType.SAVE_UPDATE) private List<Product> products=new
I have a simple situation here. lets face html code first => <form name=geoKey
I have a simple parent-child situation where the parent can have multiple children. The
The situation is very simple, I have two panel. In the event of OnMouseOver
I have a situation in C# where I have a list of simple types.
At work, we just upgraded from VS2005 to 2010. To this point, we've only

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.