我有一個WinForms應用程序原本用VB編寫並轉換爲C#。我正試圖通過與VB相比較來調試我的C#應用程序。關閉按鈕不關閉表格
我注意到,目前,我的C#應用程序中最上面的右邊紅色取消按鈕並不關閉窗體,但它在VB中。
的VB代碼是在這裏
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
的C#代碼是在這裏
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();
}
我想我錯過了一些事件處理程序,將呼籲一下關閉此功能按鈕的形式。 任何人都可以幫忙嗎?
你綁定此事件,形成 「的FormClosing」事件與否? –
如何綁定這個。它的WinForms不是WPF,否則我會直接在窗體關閉事件中添加函數名稱。這將是一個蛋糕散步 – Apoorv
您可以使用設計器中的屬性窗口來創建或選擇一個事件處理程序,您也可以在VB中執行該處理程序。沒有'Handles'子句,所以你必須顯式註冊事件處理程序,這相當於VB中的'AddHandler'。 – jmcilhinney