Minimize to tray on Alt+F4 window close

This commit is contained in:
Meik
2026-03-05 12:48:15 +01:00
parent 088e486723
commit 63f1ffc57d
2 changed files with 34 additions and 16 deletions

View File

@@ -16,6 +16,7 @@
Loaded="Window_Loaded" Loaded="Window_Loaded"
Icon="Resources/icons/logo_CustomerPanel.ico" Icon="Resources/icons/logo_CustomerPanel.ico"
KeyDown="App_KeyDown" KeyDown="App_KeyDown"
Closing="Window_Closing"
Closed="Window_Closed" Closed="Window_Closed"
SizeChanged="Window_SizeChanged"> SizeChanged="Window_SizeChanged">
<Window.Resources> <Window.Resources>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
@@ -71,6 +72,7 @@ namespace C4IT_CustomerPanel
private TimeSpan _lastTicketInterval; private TimeSpan _lastTicketInterval;
private TimeSpan _lastAdHocInterval; private TimeSpan _lastAdHocInterval;
private TimeSpan _lastRegularInterval; private TimeSpan _lastRegularInterval;
private bool _allowApplicationShutdown = false;
internal DateTime lastUpdate; internal DateTime lastUpdate;
//private Dictionary<announcementType, List<Guid>> announcementIDCollection = new Dictionary<announcementType, List<Guid>>(); //private Dictionary<announcementType, List<Guid>> announcementIDCollection = new Dictionary<announcementType, List<Guid>>();
@@ -166,7 +168,7 @@ namespace C4IT_CustomerPanel
catch (Exception E) catch (Exception E)
{ {
LogException(E); LogException(E);
Application.Current.Shutdown(); RequestApplicationShutdown();
Environment.Exit(0); Environment.Exit(0);
} }
} }
@@ -1056,12 +1058,18 @@ namespace C4IT_CustomerPanel
Application.Current.MainWindow.Topmost = false; Application.Current.MainWindow.Topmost = false;
} }
private void RequestApplicationShutdown()
{
_allowApplicationShutdown = true;
Application.Current.Shutdown();
}
private void ChangeLang(string lang) private void ChangeLang(string lang)
{ {
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
System.Windows.Forms.Application.Restart(); System.Windows.Forms.Application.Restart();
Application.Current.Shutdown(); RequestApplicationShutdown();
notifyIcon.Dispose(); notifyIcon.Dispose();
} }
@@ -1511,7 +1519,7 @@ namespace C4IT_CustomerPanel
} }
else else
{ {
Application.Current.Shutdown(); RequestApplicationShutdown();
Environment.Exit(0); Environment.Exit(0);
} }
} }
@@ -1834,19 +1842,19 @@ namespace C4IT_CustomerPanel
} }
} }
public void Button_MouseEnter(object sender, EventArgs e) public void Button_MouseEnter(object sender, EventArgs e)
{ {
try try
{ {
if (!(sender is Button bu)) if (!(sender is Button bu))
return; return;
Color hoverColor = ConfigSettings.GetButtonHoverColor(ConfigSettings.GetBackgroundColor().Color); Color hoverColor = ConfigSettings.GetButtonHoverColor(ConfigSettings.GetBackgroundColor().Color);
bu.Background = new SolidColorBrush(hoverColor); bu.Background = new SolidColorBrush(hoverColor);
} }
catch (Exception exp) catch (Exception exp)
{ {
cLogManager.LogException(exp); cLogManager.LogException(exp);
} }
} }
@@ -2073,6 +2081,15 @@ namespace C4IT_CustomerPanel
} }
} }
private void Window_Closing(object sender, CancelEventArgs e)
{
if (_allowApplicationShutdown)
return;
e.Cancel = true;
HideMainForm();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e) private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
SetLocation(); SetLocation();