From db13f82bfcccdb985402e0dbb480104aa279a85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Sun, 27 Nov 2022 16:15:57 +0800 Subject: [PATCH] Optimized restore window state --- Source/GrasscutterTools/Forms/FormMain.cs | 67 +++++++++-------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/Source/GrasscutterTools/Forms/FormMain.cs b/Source/GrasscutterTools/Forms/FormMain.cs index d92dd78..55286b9 100644 --- a/Source/GrasscutterTools/Forms/FormMain.cs +++ b/Source/GrasscutterTools/Forms/FormMain.cs @@ -41,10 +41,33 @@ namespace GrasscutterTools.Forms Icon = Resources.IconGrasscutter; if (DesignMode) return; - // 初始化页面 - InitPages(); - // 加载设置 - LoadSettings(); + + try + { + // 还原窗体位置 + if (Settings.Default.MainFormLocation != default) + { + StartPosition = FormStartPosition.Manual; + Location = Settings.Default.MainFormLocation; + Console.WriteLine("Restore window location: " + Location.ToString()); + } + + // 还原窗体大小 + if (Settings.Default.MainFormSize != default) + { + Size = Settings.Default.MainFormSize; + Console.WriteLine("Restore window size: " + Size.ToString()); + } + + // 初始化页面 + InitPages(); + // 恢复自动复制选项状态 + ChkAutoCopy.Checked = Settings.Default.AutoCopy; + } + catch (Exception ex) + { + MessageBox.Show(Resources.SettingLoadError + ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + } Console.WriteLine("FormMain ctor completed"); } @@ -93,22 +116,6 @@ namespace GrasscutterTools.Forms return page; } - /// - /// 载入设置 - /// - private void LoadSettings() - { - try - { - // 恢复自动复制选项状态 - ChkAutoCopy.Checked = Settings.Default.AutoCopy; - } - catch (Exception ex) - { - MessageBox.Show(Resources.SettingLoadError + ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - /// /// 窗体载入时触发(切换语言时会重新载入) /// @@ -131,26 +138,6 @@ namespace GrasscutterTools.Forms } } - /// - /// 第一次显示窗体时触发 - /// - protected override void OnShown(EventArgs e) - { - base.OnShown(e); - // 还原窗体位置 - if (Settings.Default.MainFormLocation != default) - { - Location = Settings.Default.MainFormLocation; - Console.WriteLine("Restore window location: " + Location.ToString()); - } - // 还原窗体大小 - if (Settings.Default.MainFormSize != default) - { - Size = Settings.Default.MainFormSize; - Console.WriteLine("Restore window size: " + Size.ToString()); - } - } - /// /// 窗口关闭后触发 ///