private readonly Sniffer _sniffer;\r
private readonly Config _config;\r
private readonly MainForm _main;\r
+ private readonly MainForm.TimeOutChecker _suppressActivate;\r
private readonly CheckBox[] _shipTypeCheckBoxes;\r
public const int PanelWidth = 217;\r
\r
_main = main;\r
_sniffer = main.Sniffer;\r
_config = main.Config;\r
+ _suppressActivate = main.SuppressActivate;\r
_shipTypeCheckBoxes = new[]\r
{\r
checkBoxSTypeBattleShip,\r
e.Cancel = true;\r
if (!Visible) // 非表示のときは保存すべき情報がないのでスキップする\r
return;\r
- if (e.CloseReason == CloseReason.FormOwnerClosing)\r
- return;\r
var config = _config.ShipList;\r
StoreShipGroupToConfig();\r
var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;\r
Hide();\r
}\r
\r
- private bool _suppressActivate = true;\r
-\r
private void ListForm_Activated(object sender, EventArgs e)\r
{\r
- if (_suppressActivate)\r
- {\r
- _suppressActivate = false;\r
+ if (_suppressActivate.Check())\r
return;\r
- }\r
- if (Owner == _main)\r
+ if (WindowState == FormWindowState.Minimized)\r
return;\r
_main.Owner = null;\r
Owner = _main;\r
BringToFront();\r
+ Owner = null;\r
}\r
\r
private void StoreShipGroupToConfig()\r
\r
private void MainForm_Load(object sender, EventArgs e)\r
{\r
+ SuppressActivate.Start();\r
RestoreLocation();\r
if (Config.HideOnMinimized && WindowState == FormWindowState.Minimized)\r
ShowInTaskbar = false;\r
\r
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)\r
{\r
- if (e.CloseReason == CloseReason.FormOwnerClosing)\r
- {\r
- e.Cancel = true;\r
- return;\r
- }\r
if (!Config.ExitSilently)\r
{\r
using (var dialog = new ConfirmDialog())\r
{\r
if (_listForm == null) // DPIが100%でないときにInitializeComponentから呼ばれるので\r
return;\r
- _listForm.WindowState = WindowState;\r
- _listForm.ShowInTaskbar = ShowInTaskbar = !(Config.HideOnMinimized && WindowState == FormWindowState.Minimized);\r
+ SuppressActivate.Start();\r
+ if (WindowState == FormWindowState.Minimized)\r
+ {\r
+ _listForm.WindowState = FormWindowState.Minimized;\r
+ if (Config.HideOnMinimized)\r
+ _listForm.ShowInTaskbar = ShowInTaskbar = false;\r
+ }\r
+ else if (_listForm.WindowState == FormWindowState.Minimized)\r
+ {\r
+ DoPaint();\r
+ _listForm.ShowInTaskbar = true;\r
+ _listForm.WindowState = FormWindowState.Normal;\r
+ }\r
+ }\r
+\r
+ private void DoPaint()\r
+ {\r
+ Application.DoEvents();\r
}\r
\r
- private bool _suppressActivate = true;\r
+ public TimeOutChecker SuppressActivate = new TimeOutChecker();\r
\r
private void MainForm_Activated(object sender, EventArgs e)\r
{\r
- if (_suppressActivate)\r
- {\r
- _suppressActivate = false;\r
+ if (SuppressActivate.Check())\r
return;\r
- }\r
- if (Owner == _listForm)\r
+ if (WindowState == FormWindowState.Minimized)\r
return;\r
_listForm.Owner = null;\r
Owner = _listForm;\r
BringToFront();\r
+ Owner = null;\r
+ }\r
+\r
+ public class TimeOutChecker\r
+ {\r
+ private DateTime _lastCheck;\r
+ private readonly TimeSpan _timeout = TimeSpan.FromMilliseconds(500);\r
+\r
+ public void Start()\r
+ {\r
+ _lastCheck = DateTime.Now;\r
+ }\r
+\r
+ public bool Check()\r
+ {\r
+ var now = DateTime.Now;\r
+ var last = _lastCheck;\r
+ _lastCheck = now;\r
+ return now - last < _timeout;\r
+ }\r
}\r
\r
private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e)\r
ShowInTaskbar = true;\r
WindowState = FormWindowState.Normal;\r
TopMost = _listForm.TopMost = Config.TopMost; // 最前面に表示されなくなることがあるのを回避する\r
- Activate();\r
}\r
\r
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)\r