From 5737da37a838aa4b43d56e75f98f6a4e78695664 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 5 Dec 2022 22:48:40 +0300 Subject: [PATCH] Add dark theme --- App.config | 3 +++ Dropper.csproj | 5 +++- Form1.Designer.cs | 31 +++++++++++++++++++++---- Form1.ThemeChanger.cs | 40 ++++++++++++++++++++++++++++++++ Form1.cs | 31 ++++++++++++++----------- Properties/Settings.Designer.cs | 12 ++++++++++ Properties/Settings.settings | 3 +++ Resources/icon.ico | Bin 67646 -> 67646 bytes 8 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 Form1.ThemeChanger.cs diff --git a/App.config b/App.config index cdbd626..4062d87 100644 --- a/App.config +++ b/App.config @@ -16,6 +16,9 @@ True + + False + diff --git a/Dropper.csproj b/Dropper.csproj index e953461..2dc7122 100644 --- a/Dropper.csproj +++ b/Dropper.csproj @@ -95,6 +95,9 @@ Form1.cs + + Form + @@ -143,7 +146,7 @@ False - Microsoft .NET Framework 4.8 %28x86 and x64%29 + Microsoft .NET Framework 4.8 %28x86 и x64%29 true diff --git a/Form1.Designer.cs b/Form1.Designer.cs index f90be52..4dcddfd 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -33,7 +33,6 @@ protected override void OnClosing(CancelEventArgs e) e.Cancel = true; this.Hide(); } - #region Windows Form Designer generated code @@ -49,6 +48,7 @@ private void InitializeComponent() this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.historyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DarkThemeCheck = new System.Windows.Forms.ToolStripMenuItem(); this.CopyCheck = new System.Windows.Forms.ToolStripMenuItem(); this.CollapseCheck = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); @@ -90,6 +90,7 @@ private void InitializeComponent() // settingsToolStripMenuItem // this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.DarkThemeCheck, this.CopyCheck, this.CollapseCheck, this.toolStripSeparator1, @@ -99,11 +100,18 @@ private void InitializeComponent() this.settingsToolStripMenuItem.Size = new System.Drawing.Size(116, 22); this.settingsToolStripMenuItem.Text = "Settings"; // + // DarkThemeCheck + // + this.DarkThemeCheck.CheckOnClick = true; + this.DarkThemeCheck.Name = "DarkThemeCheck"; + this.DarkThemeCheck.Size = new System.Drawing.Size(180, 22); + this.DarkThemeCheck.Text = "Dark theme"; + // // CopyCheck // this.CopyCheck.CheckOnClick = true; this.CopyCheck.Name = "CopyCheck"; - this.CopyCheck.Size = new System.Drawing.Size(171, 22); + this.CopyCheck.Size = new System.Drawing.Size(180, 22); this.CopyCheck.Text = "Copy to Clipboard"; // // CollapseCheck @@ -112,19 +120,19 @@ private void InitializeComponent() this.CollapseCheck.CheckOnClick = true; this.CollapseCheck.CheckState = System.Windows.Forms.CheckState.Checked; this.CollapseCheck.Name = "CollapseCheck"; - this.CollapseCheck.Size = new System.Drawing.Size(171, 22); + this.CollapseCheck.Size = new System.Drawing.Size(180, 22); this.CollapseCheck.Text = "Collapse on close"; // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(168, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6); // // toolStripMenuItem1 // this.toolStripMenuItem1.Enabled = false; this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(171, 22); + this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22); this.toolStripMenuItem1.Text = "Hotkeys"; this.toolStripMenuItem1.ToolTipText = "Alt + Shift + C - Get Color\r\nAlt + Shift + H - Show/Hide history"; // @@ -221,6 +229,7 @@ private void TrayMenuInit() CollapseCheck.CheckedChanged += SettingsChanged; CopyCheck.CheckedChanged += SettingsChanged; notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; + DarkThemeCheck.CheckedChanged += SettingsChanged; } private void TitleInit() @@ -234,6 +243,16 @@ private void TitleInit() TitleLable.MouseMove += new MouseEventHandler(TitleMouseMove); } + private void InteropServicesInit() + { + Region = System.Drawing.Region.FromHrgn(Utils.CreateRoundRectRgn(0, 0, Width, Height, 15, 15)); + + int id = 0; + Utils.RegisterHotKey(Handle, id, (int)KeyModifier.Alt + (int)KeyModifier.Shift, Keys.C.GetHashCode()); + id = 1; + Utils.RegisterHotKey(Handle, id, (int)KeyModifier.Alt + (int)KeyModifier.Shift, Keys.H.GetHashCode()); + } + private void AddItemOnPanel(Color color) { string hexColor = Utils.HexConverter(color); @@ -248,6 +267,7 @@ private void AddItemOnPanel(Color color) textBox.BorderStyle = BorderStyle.None; textBox.TabStop = false; textBox.BackColor = this.BackColor; + textBox.ForeColor = this.ForeColor; textBox.Multiline = true; textBox.AcceptsReturn = true; textBox.AppendText($"Color: {rgbColor}\r\nHEX: {hexColor}"); @@ -288,6 +308,7 @@ private void AddItemOnPanel(Color color) private Button CloseButton; private PictureBox TitleBar; private Label TitleLable; + private ToolStripMenuItem DarkThemeCheck; } } diff --git a/Form1.ThemeChanger.cs b/Form1.ThemeChanger.cs new file mode 100644 index 0000000..9701a6b --- /dev/null +++ b/Form1.ThemeChanger.cs @@ -0,0 +1,40 @@ +using System.Drawing; + +namespace Dropper +{ + partial class Form1 + { + private Color _lightBG = Color.WhiteSmoke; + private Color _lightFG = Color.FromArgb(23, 23, 23); + + private Color _darkBG = Color.FromArgb(23, 23, 23); //#2b2b2b + private Color _darkFG = Color.FromArgb(230, 230, 230); //#f1f1f1f + + public void SetDarkTheme(bool enable) + { + if (enable) + SetColors(_darkBG, _darkFG); + else + SetColors(_lightBG, _lightFG); + } + + private void SetColors(Color bg, Color fg) + { + this.BackColor = bg; + this.ForeColor = fg; + + panel1.BackColor = bg; + CloseButton.BackColor = bg; + CloseButton.ForeColor = fg; + TitleBar.BackColor = bg; + TitleLable.BackColor = bg; + TitleLable.ForeColor = fg; + + foreach(var item in textBoxes) + { + item.BackColor = bg; + item.ForeColor = fg; + } + } + } +} diff --git a/Form1.cs b/Form1.cs index 4715823..81e7395 100644 --- a/Form1.cs +++ b/Form1.cs @@ -18,17 +18,12 @@ public partial class Form1 : Form public Form1() { InitializeComponent(); + LoadSettings(); TrayMenuInit(); TitleInit(); + InteropServicesInit(); - Region = System.Drawing.Region.FromHrgn(Utils.CreateRoundRectRgn(0, 0, Width, Height, 15, 15)); - - LoadSettings(); - - int id = 0; - Utils.RegisterHotKey(Handle, id, (int)KeyModifier.Alt + (int)KeyModifier.Shift, Keys.C.GetHashCode()); - id = 1; - Utils.RegisterHotKey(Handle, id, (int)KeyModifier.Alt + (int)KeyModifier.Shift, Keys.H.GetHashCode()); + SetDarkTheme(DarkThemeCheck.Checked); } protected override void WndProc(ref Message m) @@ -67,6 +62,13 @@ private void VisualStateUpdate() Hide(); } + private void LoadSettings() + { + this.CollapseCheck.Checked = Properties.Settings.Default.CollapseCheck; + this.CopyCheck.Checked = Properties.Settings.Default.CopyToClipboard; + this.DarkThemeCheck.Checked = Properties.Settings.Default.DarkTheme; + } + #region Notify menu button methods private void MenuShowHistory_Click(object sender, EventArgs e) @@ -98,13 +100,13 @@ private void SettingsChanged(object sender, EventArgs e) Properties.Settings.Default.CopyToClipboard = this.CopyCheck.Checked; Properties.Settings.Default.Save(); break; + case "DarkThemeCheck": + Properties.Settings.Default.DarkTheme = this.DarkThemeCheck.Checked; + Properties.Settings.Default.Save(); + SetDarkTheme(DarkThemeCheck.Checked); + break; } } - private void LoadSettings() - { - this.CollapseCheck.Checked = Properties.Settings.Default.CollapseCheck; - this.CopyCheck.Checked = Properties.Settings.Default.CopyToClipboard; - } #endregion #region Title bar methods @@ -135,7 +137,8 @@ private void TitleMouseDown(object sender, MouseEventArgs e) _startPoint = e.Location; _isDrag = true; } - #endregion + + #endregion //============================================== private void GetButtonColor(object sender, EventArgs e) { diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index f5046a9..28ccc5e 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -46,5 +46,17 @@ public bool CopyToClipboard { this["CopyToClipboard"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool DarkTheme { + get { + return ((bool)(this["DarkTheme"])); + } + set { + this["DarkTheme"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 5be5460..e17abe9 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -8,5 +8,8 @@ True + + False + \ No newline at end of file diff --git a/Resources/icon.ico b/Resources/icon.ico index 7f42b1997fe4619f6ad6e8d2ee7fd4346928ab0c..0ab4f0d6093b8eb1058419f83d57a86b01ea0e8b 100644 GIT binary patch delta 25 fcmdltfo0zW7H$RxMj&ixU|?Wqx$