From ab025b39f424d15e69338bf51c528552ef6c60ce Mon Sep 17 00:00:00 2001
From: YFdyh000 <yfdyh000@gmail.com>
Date: Thu, 16 Apr 2020 08:51:02 +0800
Subject: [PATCH] Remember the size and position of the main window

---
 v2rayN/v2rayN/Forms/MainForm.cs | 15 +++++++++++++--
 v2rayN/v2rayN/Mode/Config.cs    | 11 +++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs
index ed086e2e..f0f6b29a 100644
--- a/v2rayN/v2rayN/Forms/MainForm.cs
+++ b/v2rayN/v2rayN/Forms/MainForm.cs
@@ -52,6 +52,14 @@ namespace v2rayN.Forms
             v2rayHandler = new V2rayHandler();
             v2rayHandler.ProcessEvent += v2rayHandler_ProcessEvent;
 
+            if(!config.formMainSize.IsEmpty) {
+                this.Left = config.formMainSize.X;
+                this.Top = config.formMainSize.Y;
+                this.Width = config.formMainSize.Width;
+                this.Height = config.formMainSize.Height;
+            }
+            this.WindowState = config.windowState;
+
             if (config.enableStatistics)
             {
                 statistics = new StatisticsHandler(config, UpdateStatisticsHandler);
@@ -87,6 +95,10 @@ namespace v2rayN.Forms
         {
             if (e.CloseReason == CloseReason.UserClosing)
             {
+                if (this.WindowState != FormWindowState.Maximized)
+                    config.formMainSize = new Rectangle(this.Left, this.Top, this.Width, this.Height);
+                config.windowState = this.WindowState;
+
                 e.Cancel = true;
                 HideForm();
                 return;
@@ -973,7 +985,6 @@ namespace v2rayN.Forms
 
         private void menuExit_Click(object sender, EventArgs e)
         {
-
             this.Visible = false;
             this.Close();
 
@@ -984,7 +995,7 @@ namespace v2rayN.Forms
         private void ShowForm()
         {
             this.Show();
-            this.WindowState = FormWindowState.Normal;
+            //this.WindowState = config.windowState;
             this.Activate();
             //this.notifyIcon1.Visible = false;
             this.ShowInTaskbar = true;
diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs
index 24baa514..32556e05 100644
--- a/v2rayN/v2rayN/Mode/Config.cs
+++ b/v2rayN/v2rayN/Mode/Config.cs
@@ -36,6 +36,17 @@ namespace v2rayN.Mode
             get; set;
         }
 
+        /// <summary>
+        /// 主窗口的大小和位置
+        /// </summary>
+        public System.Drawing.Rectangle formMainSize
+        {
+            get; set;
+        }
+        public System.Windows.Forms.FormWindowState windowState
+        {
+            get; set;
+        }
         /// <summary>
         /// 活动配置序号
         /// </summary>