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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:43:32+00:00 2026-05-11T09:43:32+00:00

I have a WinForms form that won’t close. In OnFormClosing, e.Cancel is set to

  • 0

I have a WinForms form that won’t close. In OnFormClosing, e.Cancel is set to true. I am guessing that some object in my application has bound to the Closing or FormClosing event, and is blocking the close. To find out, I’d like to determine what delegates are bound to one of these events.

Is there a way to determine the list of handlers bound to an event? Ideally I would do this via the Visual Studio debugger, but can write code in the application to find the handlers if necessary. Understanding that an event is like a hidden private field, I’ve navigated through the Debugger to the ‘Non-Public Fields’ for the ‘Windows.Forms.Form’ ancestor of my form, but to no avail.

  • 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. 2026-05-11T09:43:33+00:00Added an answer on May 11, 2026 at 9:43 am

    In short, you’re not meant to do this – but for debugging purposes…

    An event is often backed by a private field – but not with controls; they use the EventHandlerList approach. You would have to access the form’s protected Events member, looking for the object mapped to the (private) EVENT_FORMCLOSING object.

    Once you have the FormClosingEventHandler, GetInvocationList should do the job.


    using System; using System.ComponentModel; using System.Reflection; using System.Windows.Forms; class MyForm : Form {     public MyForm()     { // assume we don't know this...         Name = 'My Form';         FormClosing += Foo;         FormClosing += Bar;     }      void Foo(object sender, FormClosingEventArgs e) { }     void Bar(object sender, FormClosingEventArgs e) { }      static void Main()     {         Form form = new MyForm();         EventHandlerList events = (EventHandlerList)typeof(Component)             .GetProperty('Events', BindingFlags.NonPublic | BindingFlags.Instance)             .GetValue(form, null);         object key = typeof(Form)             .GetField('EVENT_FORMCLOSING', BindingFlags.NonPublic | BindingFlags.Static)             .GetValue(null);          Delegate handlers = events[key];         foreach (Delegate handler in handlers.GetInvocationList())         {             MethodInfo method = handler.Method;             string name = handler.Target == null ? '' : handler.Target.ToString();             if (handler.Target is Control) name = ((Control)handler.Target).Name;             Console.WriteLine(name + '; ' + method.DeclaringType.Name + '.' + method.Name);         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms application that dynamically instantiates external form objects for use in
I have a WinForms Application that I want to run at Mono at some
I have a WinForms Form that used to be a standalone application, but is
I have a WinForms application that, at some point, will do some calculations that
I have an application written in .net winforms. There is a form that shows
In a VB.NET Winforms application, I have a form that contains both a datagridview
I have a .NET 2.0 WinForms application with a ToolStrip on my main form.
Technologies: C#, .Net, Winforms I have a main form that pulls data from a
I have a listview control that is on a winforms form. It fills the
In my C# WinForms program, I have a form that has only a single

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.