controlapp/ControlApp/MyCustomApplicationContext.cs
2025-03-18 18:05:19 -07:00

87 lines
1.6 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
namespace ControlApp;
public class MyCustomApplicationContext : ApplicationContext
{
private NotifyIcon trayIcon;
private ControlApp myform;
public MyCustomApplicationContext()
{
trayIcon = new NotifyIcon();
trayIcon.Icon = new Icon("App.ico");
trayIcon.ContextMenuStrip = new ContextMenuStrip();
trayIcon.ContextMenuStrip.Items.Add("Exit", null, Exit);
trayIcon.ContextMenuStrip.Items.Add("Open", null, Open);
trayIcon.ContextMenuStrip.Items.Add("Panic", null, Panic);
trayIcon.ContextMenuStrip.Items.Add("Subliminal", null, Subliminal);
trayIcon.MouseClick += TrayIcon_MouseClick;
trayIcon.Visible = true;
myform = new ControlApp();
}
private void TrayIcon_MouseClick(object? sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (myform.IsDisposed)
{
myform = new ControlApp();
}
myform.Show();
}
}
private void Exit(object sender, EventArgs e)
{
trayIcon.Visible = false;
Application.Exit();
}
private void Open(object sender, EventArgs e)
{
if (myform.IsDisposed)
{
myform = new ControlApp();
}
myform.Show();
}
private void Subliminal(object sender, EventArgs e)
{
bool done = false;
foreach (Form fm in Application.OpenForms)
{
if (fm.GetType() == typeof(SubLoop))
{
SubLoop pop = (SubLoop)fm;
try
{
pop.Close();
done = true;
}
catch
{
continue;
}
break;
}
}
if (!done)
{
new SubLoop().Show();
}
}
private void Panic(object sender, EventArgs e)
{
foreach (Form openForm in Application.OpenForms)
{
openForm.Close();
}
}
}