mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 06:43:51 +02:00
add tray menu and remember window state (closes #34)
This commit is contained in:
114
MainForm.cs
114
MainForm.cs
@@ -15,6 +15,10 @@ namespace VRCX
|
||||
{
|
||||
public static MainForm Instance { get; private set; }
|
||||
public static ChromiumWebBrowser Browser { get; private set; }
|
||||
private int LastLocationX;
|
||||
private int LastLocationY;
|
||||
private int LastSizeWidth;
|
||||
private int LastSizeHeight;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -22,7 +26,10 @@ namespace VRCX
|
||||
InitializeComponent();
|
||||
try
|
||||
{
|
||||
Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
|
||||
var location = Assembly.GetExecutingAssembly().Location;
|
||||
var icon = Icon.ExtractAssociatedIcon(location);
|
||||
Icon = icon;
|
||||
TrayIcon.Icon = icon;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -52,5 +59,110 @@ namespace VRCX
|
||||
};
|
||||
Controls.Add(Browser);
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, System.EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(VRCXStorage.Instance.Get("VRCX_LocationX"), out LastLocationX);
|
||||
int.TryParse(VRCXStorage.Instance.Get("VRCX_LocationY"), out LastLocationY);
|
||||
int.TryParse(VRCXStorage.Instance.Get("VRCX_SizeWidth"), out LastSizeWidth);
|
||||
int.TryParse(VRCXStorage.Instance.Get("VRCX_SizeHeight"), out LastSizeHeight);
|
||||
var location = new Point(LastLocationX, LastLocationY);
|
||||
var size = new Size(LastSizeWidth, LastSizeHeight);
|
||||
var screen = Screen.FromPoint(location);
|
||||
if (screen.Bounds.Contains(location.X, location.Y))
|
||||
{
|
||||
Location = location;
|
||||
}
|
||||
if (size.Width > 0 && size.Height > 0)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
var state = WindowState;
|
||||
if (int.TryParse(VRCXStorage.Instance.Get("VRCX_WindowState"), out int v))
|
||||
{
|
||||
state = (FormWindowState)v;
|
||||
}
|
||||
if (state == FormWindowState.Minimized)
|
||||
{
|
||||
state = FormWindowState.Normal;
|
||||
}
|
||||
if ("true".Equals(VRCXStorage.Instance.Get("VRCX_StartAsMinimizedState")))
|
||||
{
|
||||
state = FormWindowState.Minimized;
|
||||
}
|
||||
WindowState = state;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_Resize(object sender, System.EventArgs e)
|
||||
{
|
||||
if (WindowState != FormWindowState.Normal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
LastSizeWidth = Size.Width;
|
||||
LastSizeHeight = Size.Height;
|
||||
}
|
||||
|
||||
private void MainForm_Move(object sender, System.EventArgs e)
|
||||
{
|
||||
if (WindowState != FormWindowState.Normal)
|
||||
{
|
||||
return;
|
||||
}
|
||||
LastLocationX = Location.X;
|
||||
LastLocationY = Location.Y;
|
||||
}
|
||||
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (e.CloseReason == CloseReason.UserClosing &&
|
||||
"true".Equals(VRCXStorage.Instance.Get("VRCX_CloseToTray")))
|
||||
{
|
||||
e.Cancel = true;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
VRCXStorage.Instance.Set("VRCX_LocationX", LastLocationX.ToString());
|
||||
VRCXStorage.Instance.Set("VRCX_LocationY", LastLocationY.ToString());
|
||||
VRCXStorage.Instance.Set("VRCX_SizeWidth", LastSizeWidth.ToString());
|
||||
VRCXStorage.Instance.Set("VRCX_SizeHeight", LastSizeHeight.ToString());
|
||||
VRCXStorage.Instance.Set("VRCX_WindowState", ((int)WindowState).ToString());
|
||||
}
|
||||
|
||||
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
TrayMenu_Open_Click(sender, e);
|
||||
}
|
||||
|
||||
private void TrayMenu_Open_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
if (WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
WindowState = FormWindowState.Normal;
|
||||
}
|
||||
Show();
|
||||
Focus();
|
||||
}
|
||||
|
||||
private void TrayMenu_Quit_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user