-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormStylingExtensions.cs
More file actions
60 lines (53 loc) · 2.41 KB
/
FormStylingExtensions.cs
File metadata and controls
60 lines (53 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections.Generic;
using System.Windows.Forms;
namespace RoundedFormsExample
{
public static class FormStylingExtensions
{
// Global registry of active stylers.
private static readonly List<CustomFormStyler> _stylers = new();
/// <summary>
/// Attach a new CustomFormStyler to the form and remember it.
/// </summary>
public static CustomFormStyler ApplyTheme(this Form form)
{
/// <summary>
/// Reads corner check‑boxes from MainForm, returns Corner mask.
/// (Returns Corner.All for any other window.)
/// </summary>
Corner corners = form is MainForm m
? m.SelectedCorners
: Corner.All;
var styler = new CustomFormStyler(
form,
theme: Properties.Settings.Default.UITheme,
roundedCorners: Properties.Settings.Default.UICorners,
cornerRadius: Properties.Settings.Default.UICornerRadius,
titleBarHeight: Properties.Settings.Default.UITitleBarHeight,
borderSize: Properties.Settings.Default.UIBorderSize,
showIcon: Properties.Settings.Default.UIShowIcon);
styler.Enable();
_stylers.Add(styler);
// Remove it from the list when the form dies so we don't leak.
form.FormClosed += (_, __) => _stylers.Remove(styler);
return styler;
}
/// <summary>
/// Re‑apply the *current* global settings to every open form.
/// Call this after the user changes Dark/Light, corner radius, etc.
/// </summary>
public static void RefreshAllThemes()
{
foreach (var s in _stylers.ToArray()) // ToArray - Safe if list mutates.
{
s.UpdateStyle(
theme: Properties.Settings.Default.UITheme,
roundedCorners: Properties.Settings.Default.UICorners,
cornerRadius: Properties.Settings.Default.UICornerRadius,
titleBarHeight: Properties.Settings.Default.UITitleBarHeight,
borderSize: Properties.Settings.Default.UIBorderSize,
showIcon: Properties.Settings.Default.UIShowIcon);
}
}
}
}