This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
Resizor/Resizor/SettingsForm.cs

91 lines
3.1 KiB
C#
Raw Normal View History

2020-03-08 13:55:21 +01:00
using System;
2019-09-06 20:45:42 +02:00
using System.Drawing;
2020-03-11 18:08:18 +01:00
using System.IO;
2019-09-06 20:45:42 +02:00
using System.Windows.Forms;
2020-03-08 13:55:21 +01:00
using CC_Functions.W32.Hooks;
2019-09-06 20:45:42 +02:00
using Microsoft.Win32;
namespace Resizor
{
public partial class SettingsForm : Form
{
2020-03-08 13:55:21 +01:00
private const string AppName = "Resizor";
private readonly RegistryKey _rkApp;
2019-09-06 20:45:42 +02:00
public SettingsForm()
{
InitializeComponent();
2020-03-08 13:55:21 +01:00
Program.Kh = new KeyboardHook();
2020-03-24 21:48:10 +01:00
keySelectButton.Text = Settings.ImmediateResizeKey.ToString();
2019-09-06 20:45:42 +02:00
keySelectButton.Tag = false;
2020-03-24 21:48:10 +01:00
rowsSelect.Value = Settings.ResizeDividor.Y;
columnsSelect.Value = Settings.ResizeDividor.X;
2020-03-08 13:55:21 +01:00
_rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
startupBox.Checked = _rkApp.GetValue(AppName) != null;
2019-09-06 20:45:42 +02:00
}
private void KeySelectButton_Click(object sender, EventArgs e)
{
2020-03-08 13:55:21 +01:00
if ((bool) keySelectButton.Tag)
2019-09-06 20:45:42 +02:00
{
2020-03-08 13:55:21 +01:00
Program.Kh.OnKeyPress -= Hook_OnKeyPress;
2019-09-06 20:45:42 +02:00
keySelectButton.BackColor = SystemColors.Control;
keySelectButton.Tag = false;
2020-03-24 21:48:10 +01:00
keySelectButton.Text = Settings.ImmediateResizeKey.ToString();
2019-09-06 20:45:42 +02:00
}
else
{
keySelectButton.BackColor = Color.Red;
keySelectButton.Text = "Cancel";
keySelectButton.Tag = true;
2020-03-08 13:55:21 +01:00
Program.Kh.OnKeyPress += Hook_OnKeyPress;
2019-09-06 20:45:42 +02:00
}
}
private void Hook_OnKeyPress(KeyboardHookEventArgs e)
{
2020-03-08 13:55:21 +01:00
Program.Kh.OnKeyPress -= Hook_OnKeyPress;
2019-09-06 20:45:42 +02:00
keySelectButton.BackColor = SystemColors.Control;
if (e.Key != Keys.Escape)
{
2020-03-24 21:48:10 +01:00
Settings.ImmediateResizeKey = e.Key;
Settings.Save();
2019-09-06 20:45:42 +02:00
}
2020-03-24 21:48:10 +01:00
keySelectButton.Text = Settings.ImmediateResizeKey.ToString();
2019-09-06 20:45:42 +02:00
keySelectButton.Tag = false;
}
private void RowsSelect_ValueChanged(object sender, EventArgs e)
{
2020-03-24 21:48:10 +01:00
Point tmp = Settings.ResizeDividor;
2020-03-08 13:55:21 +01:00
tmp.Y = (int) rowsSelect.Value;
2020-03-24 21:48:10 +01:00
Settings.ResizeDividor = tmp;
Settings.Save();
2019-09-06 20:45:42 +02:00
}
private void ColumnsSelect_ValueChanged(object sender, EventArgs e)
{
2020-03-24 21:48:10 +01:00
Point tmp = Settings.ResizeDividor;
2020-03-08 13:55:21 +01:00
tmp.X = (int) columnsSelect.Value;
2020-03-24 21:48:10 +01:00
Settings.ResizeDividor = tmp;
Settings.Save();
2019-09-06 20:45:42 +02:00
}
private void StartupBox_CheckedChanged(object sender, EventArgs e)
{
try
{
if (startupBox.Checked)
2020-03-11 18:08:18 +01:00
_rkApp.SetValue(AppName, Path.ChangeExtension(Application.ExecutablePath, ".exe"));
2019-09-06 20:45:42 +02:00
else
2020-03-08 13:55:21 +01:00
_rkApp.DeleteValue(AppName, false);
startupBox.Checked = _rkApp.GetValue(AppName) != null;
2019-09-06 20:45:42 +02:00
}
catch (Exception e1)
{
2020-03-08 13:55:21 +01:00
startupBox.Checked = _rkApp.GetValue(AppName) != null;
2019-09-06 20:45:42 +02:00
MessageBox.Show(e1.ToString(), "Failed");
}
}
}
2020-03-08 13:55:21 +01:00
}