From dab9555ce5e91e52d97c16912b316a8bd1071042 Mon Sep 17 00:00:00 2001 From: Marconi Gomes Date: Sat, 9 Sep 2023 22:21:53 -0300 Subject: [PATCH] refac: Moves resizing events to designer code --- AMRPC WatchDog Desktop/Window.Designer.cs | 17 +++++++++++++++-- AMRPC WatchDog Desktop/Window.cs | 16 ---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/AMRPC WatchDog Desktop/Window.Designer.cs b/AMRPC WatchDog Desktop/Window.Designer.cs index ee6845f..2b22ea0 100644 --- a/AMRPC WatchDog Desktop/Window.Designer.cs +++ b/AMRPC WatchDog Desktop/Window.Designer.cs @@ -43,7 +43,13 @@ private void InitializeComponent() this._notifyIcon.BalloonTipText = "Running in background"; this._notifyIcon.BalloonTipTitle = "AMRPC WatchDog"; this._notifyIcon.Icon = ((System.Drawing.Icon) (resources.GetObject("_notifyIcon.Icon"))); - this._notifyIcon.Click += new System.EventHandler(this.Window_Restore); + + this._notifyIcon.Click += new System.EventHandler((_, __) => + { + Show(); + WindowState = FormWindowState.Normal; + _notifyIcon.Visible = false; + }); // // _runningStatusLabel // @@ -81,7 +87,14 @@ private void InitializeComponent() this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "AMRPC WatchDog"; this.Load += new System.EventHandler(this.Window_Load); - this.Resize += new System.EventHandler(this.Window_Resize); + this.Resize += new System.EventHandler((_, __) => + { + if (WindowState == FormWindowState.Minimized) + { + Hide(); + _notifyIcon.Visible = true; + } + }); this.ResumeLayout(false); } diff --git a/AMRPC WatchDog Desktop/Window.cs b/AMRPC WatchDog Desktop/Window.cs index 4dd6648..1aba67a 100644 --- a/AMRPC WatchDog Desktop/Window.cs +++ b/AMRPC WatchDog Desktop/Window.cs @@ -31,22 +31,6 @@ private void SetupAutostartCheckbox() _autoStartCheckbox.Checked = value != null; } - private void Window_Resize(object sender, EventArgs e) - { - if (WindowState == FormWindowState.Minimized) - { - Hide(); - _notifyIcon.Visible = true; - } - } - - private void Window_Restore(object sender, EventArgs e) - { - Show(); - WindowState = FormWindowState.Normal; - _notifyIcon.Visible = false; - } - private void _autoStartCheckbox_CheckedChanged(object sender, EventArgs e) { if (((CheckBox) sender).Checked)