elfisa-pharmacy/src/ElectronicPharmacy/Classes/UiThemeHelper.cs
Magomed 7ed8822bd4 Add Dark Productivity theme with native title bar and auth dialog chrome.
Persist theme choice in settings, fix grid row colors on theme switch, and apply DWM caption styling to the main window and authorization dialog.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 19:53:30 +03:00

129 lines
4.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Drawing;
using System.Windows.Forms;
using Elfisa.UI.Controls;
using Elfisa.UI.Theming;
namespace Электроннаяармация.Classes
{
public static class UiThemeHelper
{
public static void ApplyToControlTree(Control root)
{
if (root == null)
{
return;
}
new ThemeService().Apply(root);
ApplyLegacyControls(root, ThemeManager.Colors);
}
private static void ApplyLegacyControls(Control control, ThemeColors theme)
{
if (control is ModernDataGridView modernGrid)
{
modernGrid.ApplyTheme(theme);
}
else if (control is ModernButton modernButton)
{
modernButton.ApplyTheme(theme);
if (!modernButton.HeaderNavMode && !modernButton.TopNavMode && !modernButton.SidebarMode)
{
modernButton.AllowTextEllipsis = false;
ModernButtonStyles.ApplyAuto(modernButton);
}
}
else if (control is ModernTextBox modernTextBox)
{
modernTextBox.ApplyTheme(theme);
}
else if (control is ModernNumericUpDown modernNumeric)
{
modernNumeric.ApplyTheme(theme);
}
else if (control is ModernSearchBox modernSearch)
{
modernSearch.ApplyTheme(theme);
}
else if (control is DataGridView grid)
{
grid.EnableHeadersVisualStyles = false;
grid.BackgroundColor = theme.GridRowBackground;
grid.GridColor = theme.GridBorder;
grid.ColumnHeadersDefaultCellStyle.BackColor = theme.GridHeaderBackground;
grid.ColumnHeadersDefaultCellStyle.ForeColor = theme.GridHeaderForeground;
grid.ColumnHeadersDefaultCellStyle.Font = theme.FontSemibold14;
grid.DefaultCellStyle.BackColor = theme.GridRowBackground;
grid.DefaultCellStyle.ForeColor = theme.TextPrimary;
grid.DefaultCellStyle.SelectionBackColor = theme.GridRowSelected;
grid.DefaultCellStyle.SelectionForeColor = theme.GridRowSelectedText;
grid.DefaultCellStyle.Font = theme.FontRegular13;
grid.AlternatingRowsDefaultCellStyle.BackColor = theme.GridRowAlternate;
}
else if (control is Button button)
{
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderColor = theme.Border;
button.BackColor = theme.Surface;
button.ForeColor = theme.TextPrimary;
button.Font = theme.FontRegular13;
}
else if (control is TextBox textBox)
{
textBox.BackColor = theme.InputBackground;
textBox.ForeColor = theme.TextPrimary;
textBox.BorderStyle = BorderStyle.FixedSingle;
textBox.Font = theme.FontRegular13;
}
else if (control is NumericUpDown numeric)
{
numeric.BackColor = theme.InputBackground;
numeric.ForeColor = theme.TextPrimary;
numeric.Font = theme.FontRegular13;
}
else if (control is CheckBox checkBox)
{
checkBox.ForeColor = theme.TextPrimary;
checkBox.Font = theme.FontRegular13;
}
else if (control is Label label)
{
label.ForeColor = theme.TextPrimary;
label.Font = theme.FontRegular13;
}
else if (control is TabControl tabControl)
{
tabControl.BackColor = theme.BackgroundSecondary;
tabControl.Font = theme.FontRegular13;
}
else if (control is ToolStrip toolStrip)
{
toolStrip.BackColor = theme.TitleBarBottom;
toolStrip.ForeColor = Color.White;
}
else if (control is Panel || control is UserControl || control is TableLayoutPanel || control is SplitContainer)
{
if (control.Tag as string == "keep-bg")
{
// preserve custom background
}
else if (control.Tag as string == "chrome-child")
{
control.BackColor = theme.BackgroundPrimary;
control.ForeColor = theme.TextPrimary;
}
else
{
control.BackColor = theme.BackgroundSecondary;
control.ForeColor = theme.TextPrimary;
}
}
foreach (Control child in control.Controls)
{
ApplyLegacyControls(child, theme);
}
}
}
}