[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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