OSDN Git Service

ウィンドウの位置を保存する
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Fri, 1 Aug 2014 11:54:18 +0000 (20:54 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Fri, 1 Aug 2014 13:10:05 +0000 (22:10 +0900)
KancolleSniffer/Config.cs
KancolleSniffer/MainForm.cs

index 110dbe9..1f5b3ef 100644 (file)
@@ -16,6 +16,7 @@
 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
 \r
 using System.Collections.Generic;\r
+using System.Drawing;\r
 using System.IO;\r
 using System.Windows.Forms;\r
 using Codeplex.Data;\r
@@ -26,6 +27,7 @@ namespace KancolleSniffer
     {\r
         private readonly string _configFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.json");\r
 \r
+        public Point Location { get; set; }\r
         public bool TopMost { get; set; }\r
         public bool FlashWindow { get; set; }\r
         public bool ShowBaloonTip { get; set; }\r
@@ -41,6 +43,7 @@ namespace KancolleSniffer
 \r
         public Config()\r
         {\r
+            Location = new Point(int.MinValue, int.MinValue);\r
             FlashWindow = ShowBaloonTip = PlaySound = true;\r
             MarginShips = 4;\r
             ResetHours = new List<int>();\r
index 8518030..f22ec00 100644 (file)
@@ -111,6 +111,7 @@ namespace KancolleSniffer
         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)\r
         {\r
             FiddlerApplication.Shutdown();\r
+            _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;\r
             _config.Save();\r
             _sniffer.SaveState();\r
         }\r
@@ -145,6 +146,17 @@ namespace KancolleSniffer
             _wmp.settings.volume = _config.SoundVolume;\r
             _sniffer.Item.MarginShips = _config.MarginShips;\r
             _sniffer.Achievement.ResetHours = _config.ResetHours;\r
+            if (_config.Location.X == int.MinValue)\r
+                return;\r
+            var newBounds = Bounds;\r
+            newBounds.Location = _config.Location;\r
+            if (IsVisibleOnAnyScreen(newBounds))\r
+                Location = _config.Location;\r
+        }\r
+\r
+        private bool IsVisibleOnAnyScreen(Rectangle rect)\r
+        {\r
+            return Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(rect));\r
         }\r
 \r
         private void timerMain_Tick(object sender, EventArgs e)\r