Skip to content

Commit

Permalink
Support dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thgossler committed Nov 26, 2024
1 parent dcfd0ae commit 2389f09
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# WFO5002: Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
dotnet_diagnostic.WFO5002.severity = none

# WFO5001: Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
dotnet_diagnostic.WFO5001.severity = none
17 changes: 17 additions & 0 deletions AzTagger/AzureContextConfigDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AzTagger.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace AzTagger;
Expand All @@ -23,6 +24,22 @@ public AzureContextConfigDialog(Settings settings)

_dataGridView.AutoGenerateColumns = false;
_dataGridView.DataSource = _tempAzureContexts;

if (Application.IsDarkModeEnabled)
{
_dataGridView.BackgroundColor = Color.FromArgb(30, 30, 30);
_dataGridView.ForeColor = Color.White;
_dataGridView.GridColor = Color.FromArgb(45, 45, 45);
_dataGridView.DefaultCellStyle.BackColor = Color.FromArgb(30, 30, 30);
_dataGridView.DefaultCellStyle.ForeColor = Color.White;
_dataGridView.DefaultCellStyle.SelectionBackColor = Color.FromArgb(51, 153, 255);
_dataGridView.DefaultCellStyle.SelectionForeColor = Color.Black;
_dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 45);
_dataGridView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
_dataGridView.EnableHeadersVisualStyles = false;
_dataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 45);
_dataGridView.AlternatingRowsDefaultCellStyle.ForeColor = Color.White;
}
}

private void Form_Load(object sender, EventArgs e)
Expand Down
13 changes: 7 additions & 6 deletions AzTagger/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 54 additions & 1 deletion AzTagger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public MainForm(Settings settings)
_tooltipTimer = new Timer();
_tooltipTimer.Interval = _toolTip.AutomaticDelay;
_tooltipTimer.Tick += ToolTipTimer_Tick;

if (Application.IsDarkModeEnabled)
{
SetLinkLabelColors(this, Color.LightBlue, Color.DeepSkyBlue);
}
}

private void InitializeResultsDataGridViewContextMenu()
Expand Down Expand Up @@ -242,7 +247,22 @@ private void InitializeResultsDataGridView()
_gvwResults.MouseLeave += DataGridView_Results_MouseLeave;
_gvwResults.DataSource = new List<Resource>();

// Prevent automatic sorting when a column header is double-clicked
if (Application.IsDarkModeEnabled)
{
_gvwResults.BackgroundColor = Color.FromArgb(30, 30, 30);
_gvwResults.ForeColor = Color.White;
_gvwResults.GridColor = Color.FromArgb(45, 45, 45);
_gvwResults.DefaultCellStyle.BackColor = Color.FromArgb(30, 30, 30);
_gvwResults.DefaultCellStyle.ForeColor = Color.White;
_gvwResults.DefaultCellStyle.SelectionBackColor = Color.FromArgb(51, 153, 255);
_gvwResults.DefaultCellStyle.SelectionForeColor = Color.Black;
_gvwResults.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 45);
_gvwResults.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
_gvwResults.EnableHeadersVisualStyles = false;
_gvwResults.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 45);
_gvwResults.AlternatingRowsDefaultCellStyle.ForeColor = Color.White;
}

foreach (DataGridViewColumn column in _gvwResults.Columns)
{
column.SortMode = DataGridViewColumnSortMode.NotSortable;
Expand All @@ -266,6 +286,22 @@ private void InitializeTagsDataGridView()
_gvwTags.AutoGenerateColumns = true;
_gvwTags.CellFormatting += DataGridView_Results_CellFormatting;
_gvwTags.KeyDown += DataGridView_Tags_KeyDown;

if (Application.IsDarkModeEnabled)
{
_gvwTags.BackgroundColor = Color.FromArgb(30, 30, 30);
_gvwTags.ForeColor = Color.White;
_gvwTags.GridColor = Color.FromArgb(45, 45, 45);
_gvwTags.DefaultCellStyle.BackColor = Color.FromArgb(30, 30, 30);
_gvwTags.DefaultCellStyle.ForeColor = Color.White;
_gvwTags.DefaultCellStyle.SelectionBackColor = Color.FromArgb(51, 153, 255);
_gvwTags.DefaultCellStyle.SelectionForeColor = Color.Black;
_gvwTags.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 45);
_gvwTags.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
_gvwTags.EnableHeadersVisualStyles = false;
_gvwTags.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 45);
_gvwTags.AlternatingRowsDefaultCellStyle.ForeColor = Color.White;
}
}

private void InitializeDebounceTimers()
Expand All @@ -287,6 +323,23 @@ private void InitializeResizeTimer()
_resizeTimer.Start();
}

private void SetLinkLabelColors(Control parent, Color linkColor, Color activeLinkColor)
{
foreach (Control ctrl in parent.Controls)
{
if (ctrl is LinkLabel linkLabel)
{
linkLabel.LinkColor = linkColor;
linkLabel.ActiveLinkColor = activeLinkColor;
}

if (ctrl.HasChildren)
{
SetLinkLabelColors(ctrl, linkColor, activeLinkColor);
}
}
}

private async void Form_Load(object sender, EventArgs e)
{
RestoreLastWindowState();
Expand Down
2 changes: 1 addition & 1 deletion AzTagger/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Thomas Gossler, 2024. All rights reserved.
// Licensed under the MIT license.

using AzTagger.Models;
using AzTagger.Services;
using Serilog;
using System;
Expand Down Expand Up @@ -34,6 +33,7 @@ static void Main()
}

Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.SetColorMode(SystemColorMode.System);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(settings));
Expand Down
3 changes: 0 additions & 3 deletions AzTagger/___local.settings.json

This file was deleted.

0 comments on commit 2389f09

Please sign in to comment.