• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Handles MyBase.Closing Event to C#

Can some one please tell how to add this VB event Handler to a C# program

Private Sub Form_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
  ...
End Sub
0
wenyonk
Asked:
wenyonk
  • 3
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
protected override void Form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
0
 
AlexFMCommented:
       this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
           
        }
0
 
AlexFMCommented:
To explain different parameters: my code is for C# 8.0.
In C# 7.1 and C# 8.0 you can use text editor to add event handlers (if you don't want to do this using Form Designer). Type:
this.FormClosing +=
and editor suggests you to press Tab. Press tab, editor completes the line:
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
Press Tab again, and editor adds event handler function.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
wenyonkAuthor Commented:
My original method was on an inherited form , note the Handles Mybase.Closing

does it make a difference that the event is on the from the base class?
0
 
wenyonkAuthor Commented:
maybe something like this in the frm.designer.cs??

base.Closing += new System.ComponentModel.CancelEventHandler(BaseDetailsForm_Closing);
0
 
AlexFMCommented:
In any case, Closing event belongs to the Form class, so this.Closing, base.Closing is the same event.

base.Closing += new System.ComponentModel.CancelEventHandler(BaseDetailsForm_Closing);
this.Closing += new System.ComponentModel.CancelEventHandler(BaseDetailsForm_Closing);

You can use any version you like.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now