mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Am able to minimise on start, or run normally using a simple checkbox on the main form. Maintains the setting over different runs using a settings json file stored in the AppData directory.
191 lines
6.5 KiB
C#
191 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using HeliosPlus.GameLibraries;
|
|
using System.Threading;
|
|
using System.Reflection;
|
|
using HeliosPlus.Shared;
|
|
|
|
namespace HeliosPlus.UIForms
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
|
|
private bool allowVisible; // ContextMenu's Show command used
|
|
private bool allowClose; // ContextMenu's Exit command used
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
btn_setup_display_profiles.Parent = splitContainer1.Panel1;
|
|
btn_setup_game_shortcuts.Parent = splitContainer1.Panel2;
|
|
lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version);
|
|
notifyIcon.Visible = true;
|
|
RefreshNotifyIconMenus();
|
|
|
|
if (Program.AppProgramSettings.MinimiseOnStart)
|
|
{
|
|
// Make the form minimised on start
|
|
allowVisible = false;
|
|
// Hide the application to notification area when the form is closed
|
|
allowClose = false;
|
|
cb_minimise_notification_area.Checked = true;
|
|
}
|
|
else
|
|
{
|
|
// Make the form show to the user on startup
|
|
allowVisible = true;
|
|
// Really close the application when the form is closed
|
|
allowClose = true;
|
|
cb_minimise_notification_area.Checked = false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
protected override void SetVisibleCore(bool value)
|
|
{
|
|
if (!allowVisible)
|
|
{
|
|
value = false;
|
|
if (!this.IsHandleCreated) CreateHandle();
|
|
}
|
|
base.SetVisibleCore(value);
|
|
}
|
|
|
|
protected override void OnFormClosing(FormClosingEventArgs e)
|
|
{
|
|
if (!allowClose)
|
|
{
|
|
this.Hide();
|
|
e.Cancel = true;
|
|
}
|
|
base.OnFormClosing(e);
|
|
}
|
|
|
|
private void btn_exit_Click(object sender, EventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
|
|
private void pb_display_profile_Click(object sender, EventArgs e)
|
|
{
|
|
var displayProfileForm = new DisplayProfileForm();
|
|
displayProfileForm.ShowDialog(this);
|
|
}
|
|
|
|
private void btn_setup_display_profiles_Click(object sender, EventArgs e)
|
|
{
|
|
var displayProfileForm = new DisplayProfileForm();
|
|
displayProfileForm.ShowDialog(this);
|
|
}
|
|
|
|
private void pb_game_shortcut_Click(object sender, EventArgs e)
|
|
{
|
|
var shortcutForm = new ShortcutForm();
|
|
shortcutForm.ShowDialog(this);
|
|
}
|
|
|
|
private void btn_setup_game_shortcuts_Click(object sender, EventArgs e)
|
|
{
|
|
var shortcutLibraryForm = new ShortcutLibraryForm();
|
|
shortcutLibraryForm.ShowDialog(this);
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
// Start loading the Steam Games just after the Main form opens
|
|
//SteamGame.GetAllInstalledGames();
|
|
}
|
|
|
|
private void RefreshNotifyIconMenus()
|
|
{
|
|
// Clear all the profiles
|
|
profileToolStripMenuItem.DropDownItems.Clear();
|
|
// Prepare the heading shortcuts
|
|
ToolStripMenuItem heading = new ToolStripMenuItem();
|
|
heading.Text = "Display Profiles";
|
|
Font headingFont = new Font(heading.Font, FontStyle.Italic);
|
|
heading.Font = headingFont;
|
|
heading.Enabled = false;
|
|
profileToolStripMenuItem.DropDownItems.Add(heading);
|
|
ToolStripSeparator separator = new ToolStripSeparator();
|
|
profileToolStripMenuItem.DropDownItems.Add(separator);
|
|
|
|
// Add the current slist of profiles into the NotifyIcon context menu
|
|
foreach (ProfileItem profile in ProfileRepository.AllProfiles)
|
|
{
|
|
profileToolStripMenuItem.DropDownItems.Add(profile.Name,profile.ProfileBitmap, runProfileToolStripMenuItem_Click);
|
|
}
|
|
|
|
// Clear all the shortcuts
|
|
shortcutToolStripMenuItem.DropDownItems.Clear();
|
|
// Prepare the heading shortcuts
|
|
heading = new ToolStripMenuItem();
|
|
heading.Text = "Game Shortcuts";
|
|
heading.Font = headingFont;
|
|
heading.Enabled = false;
|
|
shortcutToolStripMenuItem.DropDownItems.Add(heading);
|
|
separator = new ToolStripSeparator();
|
|
shortcutToolStripMenuItem.DropDownItems.Add(separator);
|
|
// Add the current list of profiles into the NotifyIcon context menu
|
|
foreach (ShortcutItem shortcut in ShortcutRepository.AllShortcuts)
|
|
{
|
|
shortcutToolStripMenuItem.DropDownItems.Add(shortcut.Name,shortcut.ShortcutBitmap, runShortcutToolStripMenuItem_Click);
|
|
}
|
|
|
|
}
|
|
|
|
private void runProfileToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
this.Show();
|
|
}
|
|
|
|
private void runShortcutToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
this.Show();
|
|
}
|
|
|
|
private void openApplicationWindowToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
allowVisible = true;
|
|
Show();
|
|
BringToFront();
|
|
}
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
allowClose = true;
|
|
Application.Exit();
|
|
}
|
|
|
|
private void cb_minimise_notification_area_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (cb_minimise_notification_area.Checked)
|
|
{
|
|
// Make the form minimised on start
|
|
allowVisible = false;
|
|
// Hide the application to notification area when the form is closed
|
|
allowClose = false;
|
|
// Enable the MinimiseOnStart setting
|
|
Program.AppProgramSettings.MinimiseOnStart = true;
|
|
}
|
|
else
|
|
{
|
|
// Make the form show to the user on startup
|
|
allowVisible = true;
|
|
// Really close the application when the form is closed
|
|
allowClose = true;
|
|
// Disable the MinimiseOnStart setting
|
|
Program.AppProgramSettings.MinimiseOnStart = false;
|
|
}
|
|
}
|
|
}
|
|
}
|