Form closing event not firing in win C#

Gani_tpt 2,046 Reputation points

when i right click the form, form will be closed but, event not firing. i don't know why...?

i am not able to paste the code. i have taken the screenshot. below code for your reference.


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,512 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 82,491 Reputation points

    Have you added :

    this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing);

    (automatically added when you double-click in the Designer)

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,286 Reputation points

    Try the following

    Paste into form

    const int WM_CONTEXTMENU = 0x007B;  
    protected override void WndProc(ref Message m)  
        if (m.Msg == WM_CONTEXTMENU)  
            m.Result = IntPtr.Zero;  
            base.WndProc(ref m);  

    In the form constructor

    Type Closing += press TAB which should give you an event e.g. where I added a MessageBox


    Once you have right clicked the MessageBox is shown then the form closes.

    0 comments No comments