diff --git a/KeyboardChatterBlocker/MainBlockerForm.cs b/KeyboardChatterBlocker/MainBlockerForm.cs index cfdd12a..4629739 100644 --- a/KeyboardChatterBlocker/MainBlockerForm.cs +++ b/KeyboardChatterBlocker/MainBlockerForm.cs @@ -30,26 +30,23 @@ public partial class MainBlockerForm : Form /// /// Whether the form is currently hidden from view. /// - public bool IsHidden => !ShowInTaskbar; + public bool IsHidden => !Visible; /// /// Shows the form fully and properly. - /// There are some issues with how Windows Forms handles hidden forms, this is to compensate for those. /// public void ShowForm() { - WindowState = FormWindowState.Normal; - ShowInTaskbar = true; + Visible = true; } /// /// Hides the form fully and properly. - /// There are some issues with how Windows Forms handles hidden forms, this is to compensate for those. /// public void HideForm() { - WindowState = FormWindowState.Minimized; - ShowInTaskbar = false; + TrayIcon.Visible = true; + Visible = false; } /// @@ -59,7 +56,8 @@ public MainBlockerForm() { if (Program.HideInSystemTray) { - HideForm(); + WindowState = FormWindowState.Minimized; + ShowInTaskbar = false; } Program.Blocker.KeyBlockedEvent += LogKeyBlocked; InitializeComponent(); @@ -162,7 +160,18 @@ public void MainBlockerForm_Load(object sender, EventArgs e) TrayIconCheckbox.Checked = Program.HideInSystemTray; if (Program.HideInSystemTray) { + WindowState = FormWindowState.Minimized; + ShowInTaskbar = false; TrayIcon.Visible = true; + Timer hideProperlyTimer = new Timer() { Interval = 100 }; + hideProperlyTimer.Tick += (tickSender, tickArgs) => + { + WindowState = FormWindowState.Normal; + ShowInTaskbar = true; + Visible = false; + hideProperlyTimer.Stop(); + }; + hideProperlyTimer.Start(); } ChatterThresholdBox.Value = Program.Blocker.GlobalChatterTimeLimit; EnabledCheckbox.Checked = Program.Blocker.IsEnabled;