I have a WinForms application written in VB originally and converted to C#. I am trying to debug my C# application by comparing with the VB counterpart.
What I notice, currently, is that the Topmost Right red color Cancel button in My C# application doesn't close the Form but it does in VB.
The VB code is here
Private Sub frmMain_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim Cancel As Boolean = eventArgs.Cancel
Dim ErrorFlag As ErrorFlagType = InitErrorFlag()
Dim UnloadMode As System.Windows.Forms.CloseReason = eventArgs.CloseReason
Dim SavePath As String
SavePath = System.IO.Path.Combine(ConfigSoftData.DirectoryData.AppPath, "Mold\lib")
SaveSoftConfig(SavePath, ConfigSoftData, ErrorFlag)
CheckDirectoryExists(SavePath)
StatusText = ""
eventArgs.Cancel = Cancel
My.Settings.MainScreenLeft = Me.Left
My.Settings.MainScreenTop = Me.Top
My.Settings.MainScreenWidth = Me.Width
My.Settings.Save()
End Sub
The C# code is here
private void frmMain_FormClosing(System.Object eventSender, System.Windows.Forms.FormClosingEventArgs eventArgs)
{
bool Cancel = eventArgs.Cancel;
Mold_Power_Suite.Model.FrontEndStructures.ErrorFlagType ErrorFlag = FrontEndStructures.InitErrorFlag();
System.Windows.Forms.CloseReason UnloadMode = eventArgs.CloseReason;
string SavePath = null;
SavePath = System.IO.Path.Combine(ModSoftFrontEndGlobalVariables.ConfigSoftData.DirectoryData.AppPath, "Mold\\lib");
ModSoftConfiguration.SaveSoftConfig(ref SavePath,ref ModSoftFrontEndGlobalVariables.ConfigSoftData,ref ErrorFlag);
ModSoftCalculations. CheckDirectoryExists(ref SavePath);
ModSoftFrontEndGlobalVariables.StatusText = "";
eventArgs.Cancel = Cancel;
Properties.Settings.Default.MainScreenLeft = this.Left;
// My.Settings.MainScreenLeft = this.Left;
Properties.Settings.Default.MainScreenTop = this.Top;
// My.Settings.MainScreenTop = this.Top;
Properties.Settings.Default.MainScreenWidth = this.Width;
//My.Settings.MainScreenWidth = this.Width;
Properties.Settings.Default.Save();
}
I think I am missing some event handler that would call this function on clicking the Close button in the form.

Handlesclause so you must register the event handler explicitly, which is equivalent toAddHandlerin VB. - jmcilhinney