Skip to content

Commit 3f5d491

Browse files
authored
Merge pull request #2493 from Krypton-Suite/2492-bug-kryptonform-does-not-display-administrator-when-elevated
* Resolved #2492
2 parents f12a25d + 7bafdfb commit 3f5d491

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

Documents/Changelog/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
====
44

55
## 2025-11-xx - Build 2511 (V10 - alpha) - November 2025
6+
* Resolved [#2492](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2492), `KryptonForm` does not display '(Administrator)' when elevated
67
* Resolved [#2502](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2502), **[Breaking Change]** `KryptonCommandLinkButton` updates several properties and their behaviour. See issue for full details.
78
* Resolved [#2495](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2495), `KryptonProgressBar` private field `_mementoContent` can be null.
89
* Resolved [#2490](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2490), `KryptonComboBox` uses an incorrect Items editor string.

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonForm.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ public KryptonForm()
227227
// Hook into value changes to keep them synchronized
228228
_themedSystemMenuValues.PropertyChanged += OnThemedSystemMenuValuesChanged;
229229

230+
// Initialize administrator mode detection
231+
_ = GetIsInAdministratorMode();
232+
230233
// Create the manager for handling tooltips
231234
ToolTipManager = new ToolTipManager(new ToolTipValues(null, GetDpiFactor)); // use default, as each button "could" have different values ??!!??
232235
ToolTipManager.ShowToolTip += OnShowToolTip;
@@ -1417,9 +1420,19 @@ public Color GetImageTransparentColor(PaletteState state) =>
14171420
/// Gets the short text used as the main caption title.
14181421
/// </summary>
14191422
/// <returns>Title string.</returns>
1420-
public string GetShortText() =>
1421-
// Return the existing form text property.
1422-
Text;
1423+
public string GetShortText()
1424+
{
1425+
// Get the base form text
1426+
string titleText = Text;
1427+
1428+
// Append administrator suffix if enabled and running with elevated privileges
1429+
if (KryptonManager.UseAdministratorSuffix && IsInAdministratorMode)
1430+
{
1431+
titleText += $" ({KryptonManager.Strings.GeneralStrings.Administrator})";
1432+
}
1433+
1434+
return titleText;
1435+
}
14231436

14241437
/// <summary>
14251438
/// Gets the long text used as the secondary caption title.

Source/Krypton Components/Krypton.Toolkit/Controls Toolkit/KryptonManager.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public sealed class KryptonManager : Component
2626
// Initialize the global state
2727
private static bool _globalApplyToolstrips = true;
2828
private static bool _globalUseThemeFormChromeBorderWidth = true;
29+
private static bool _globalShowAdministratorSuffix = true;
2930
internal static bool _globalUseKryptonFileDialogs = true;
3031
private static Font? _baseFont;
3132

@@ -212,6 +213,7 @@ protected override void Dispose(bool disposing)
212213
ShouldSerializeToolkitColors() ||
213214
ShouldSerializeGlobalApplyToolstrips() ||
214215
ShouldSerializeGlobalUseThemeFormChromeBorderWidth() ||
216+
ShouldSerializeShowAdministratorSuffix() ||
215217
ShouldSerializeToolkitStrings() ||
216218
ShouldSerializeUseKryptonFileDialogs() ||
217219
ShouldSerializeBaseFont() ||
@@ -226,6 +228,7 @@ public void Reset()
226228
ResetToolkitColors();
227229
ResetGlobalApplyToolstrips();
228230
ResetGlobalUseThemeFormChromeBorderWidth();
231+
ResetShowAdministratorSuffix();
229232
ResetToolkitStrings();
230233
ResetUseKryptonFileDialogs();
231234
ResetBaseFont();
@@ -403,6 +406,20 @@ public bool GlobalUseThemeFormChromeBorderWidth
403406

404407
private void ResetToolkitColors() => Colors.Reset();
405408

409+
/// <summary>
410+
/// Gets or sets a value indicating if the administrator suffix should be shown in KryptonForm title bars.
411+
/// </summary>
412+
[Category(@"Visuals")]
413+
[Description(@"Should the administrator suffix be shown in KryptonForm title bars when running with elevated privileges.")]
414+
[DefaultValue(true)]
415+
public bool ShowAdministratorSuffix
416+
{
417+
get => UseAdministratorSuffix;
418+
set => UseAdministratorSuffix = value;
419+
}
420+
private bool ShouldSerializeShowAdministratorSuffix() => !UseAdministratorSuffix;
421+
private void ResetShowAdministratorSuffix() => UseAdministratorSuffix = true;
422+
406423
#endregion
407424

408425
#region Static Properties
@@ -419,6 +436,27 @@ public bool GlobalUseThemeFormChromeBorderWidth
419436
/// <value>The colors.</value>
420437
public static KryptonColorStorage Colors { get; } = new KryptonColorStorage();
421438

439+
#region Static ShowAdministratorSuffix
440+
/// <summary>
441+
/// Gets and sets the global flag that decides if administrator suffix should be shown in KryptonForm title bars.
442+
/// </summary>
443+
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
444+
public static bool UseAdministratorSuffix
445+
{
446+
get => _globalShowAdministratorSuffix;
447+
448+
set
449+
{
450+
// Only interested if the value changes
451+
if (_globalShowAdministratorSuffix != value)
452+
{
453+
// Use new value
454+
_globalShowAdministratorSuffix = value;
455+
}
456+
}
457+
}
458+
#endregion
459+
422460
#endregion
423461

424462
#region Static ApplyToolstrips

Source/Krypton Components/Krypton.Toolkit/Translations/General/GeneralToolkitStrings.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace Krypton.Toolkit;
1616
public class GeneralToolkitStrings : GlobalId
1717
{
1818
#region Static Fields
19+
20+
private const string DEFAULT_ADMINISTRATOR = @"Administrator";
1921
private const string DEFAULT_OK = @"O&K"; // Accelerator key - K
2022
private const string DEFAULT_CANCEL = @"Cance&l"; // Accelerator key - L
2123
private const string DEFAULT_YES = @"&Yes"; // Accelerator key - Y
@@ -60,7 +62,8 @@ public GeneralToolkitStrings()
6062
/// </summary>
6163
/// <returns>True if all values are defaulted; otherwise false.</returns>
6264
[Browsable(false)]
63-
public bool IsDefault => OK.Equals(DEFAULT_OK) &&
65+
public bool IsDefault => Administrator.Equals(DEFAULT_ADMINISTRATOR) &&
66+
OK.Equals(DEFAULT_OK) &&
6467
Cancel.Equals(DEFAULT_CANCEL) &&
6568
Yes.Equals(DEFAULT_YES) &&
6669
No.Equals(DEFAULT_NO) &&
@@ -82,6 +85,7 @@ public GeneralToolkitStrings()
8285
/// </summary>
8386
public void Reset()
8487
{
88+
Administrator = DEFAULT_ADMINISTRATOR;
8589
OK = DEFAULT_OK;
8690
Cancel = DEFAULT_CANCEL;
8791
Yes = DEFAULT_YES;
@@ -106,6 +110,16 @@ public void Reset()
106110
LessDetails = DEFAULT_LESS_DETAILS;*/
107111
}
108112

113+
/// <summary>
114+
/// Gets and sets the Administrator string used in KryptonForm.
115+
/// </summary>
116+
[Localizable(true)]
117+
[Category(@"Visuals")]
118+
[Description(@"Administrator string used for KryptonForm.")]
119+
[DefaultValue(DEFAULT_ADMINISTRATOR)]
120+
[RefreshProperties(RefreshProperties.All)]
121+
public string Administrator { get; set; }
122+
109123
/// <summary>
110124
/// Gets and sets the OK string used in message box buttons.
111125
/// </summary>

0 commit comments

Comments
 (0)