restore standard window controls, minimize-to-tray, close-exits

- Restore default FormBorderStyle (resizable with min/max/close buttons)
- Minimize button hides to tray (WindowState=Minimized -> Hide())
- Close button and tray Exit both call Shutdown() then close normally
- Tray Show/DoubleClick restores window from tray
This commit is contained in:
2026-08-13 08:11:16 +00:00
parent 54c804f81f
commit d1e71f0323
2 changed files with 14 additions and 11 deletions
+11 -9
View File
@@ -17,9 +17,6 @@ public partial class MainForm : Form
Text = "gatuna"; Text = "gatuna";
Width = 520; Width = 520;
Height = 380; Height = 380;
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
MinimizeBox = false;
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
InitializeComponents(); InitializeComponents();
@@ -146,14 +143,19 @@ public partial class MainForm : Form
} }
} }
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (WindowState == FormWindowState.Minimized)
{
Hide();
WindowState = FormWindowState.Normal;
}
}
protected override void OnFormClosing(FormClosingEventArgs e) protected override void OnFormClosing(FormClosingEventArgs e)
{ {
if (e.CloseReason == CloseReason.UserClosing) Shutdown();
{
e.Cancel = true;
Hide();
return;
}
base.OnFormClosing(e); base.OnFormClosing(e);
} }
+3 -2
View File
@@ -20,18 +20,19 @@ static class Program
tray.ContextMenuStrip.Items.Add("Show", null, (_, _) => tray.ContextMenuStrip.Items.Add("Show", null, (_, _) =>
{ {
form.Show(); form.Show();
form.WindowState = FormWindowState.Normal;
form.Activate(); form.Activate();
}); });
tray.ContextMenuStrip.Items.Add("-"); tray.ContextMenuStrip.Items.Add("-");
tray.ContextMenuStrip.Items.Add("Exit", null, (_, _) => tray.ContextMenuStrip.Items.Add("Exit", null, (_, _) =>
{ {
form.Shutdown();
tray.Visible = false; tray.Visible = false;
Application.Exit(); form.Close();
}); });
tray.DoubleClick += (_, _) => tray.DoubleClick += (_, _) =>
{ {
form.Show(); form.Show();
form.WindowState = FormWindowState.Normal;
form.Activate(); form.Activate();
}; };