Skip to content

Commit 2b966f1

Browse files
authored
Merge pull request #2915 from Krypton-Suite/V105-LTS-2910-bug-kryptoncombobox-override-font-property-causes-form-designer-error
* `KryptonComboBox` override Font property causes form designer error…
2 parents 4da4f2c + b80f223 commit 2b966f1

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

Documents/Changelog/Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
====
44

5+
## 2026-04-20 - Build 2604 (Version 105-LTS - Patch 2) - April 2026
6+
7+
* Resolved [#2910](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2910), `KryptonComboBox` override Font property causes form designer error
8+
9+
====
10+
511
# 2026-01-19 - Build 2501 (Version 105-LTS - Patch 1) - January 2026
612

713
* Resolved/Implemented [#1651](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1651), KComboBox's should follow the DateTimePicker layout(s)

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,15 @@ public override Color BackColor
14611461
[AllowNull]
14621462
public override Font Font
14631463
{
1464-
get => base.Font;
1464+
get => GetStateCommonFont() ?? base.Font;
14651465

1466-
set => base.Font = value!;
1466+
set
1467+
{
1468+
// Always set base.Font to ensure consistency
1469+
base.Font = value!;
1470+
// Also try to set StateCommon font, but don't fail if it's not available
1471+
SetStateCommonFont(value);
1472+
}
14671473
}
14681474

14691475
/// <summary>
@@ -2435,6 +2441,54 @@ protected virtual void OnHoverSelectionChanged(HoveredSelectionChangedEventArgs
24352441
/// </summary>
24362442
/// <param name="e"></param>
24372443
protected virtual void OnToolTipNeeded(ToolTipNeededEventArgs e) => ToolTipNeeded?.Invoke(this, e);
2444+
2445+
/// <summary>
2446+
/// Gets the font from StateCommon.ComboBox.Content.Font safely, handling design mode serialization issues.
2447+
/// </summary>
2448+
/// <returns>The font from StateCommon, or null if not available or during problematic design time access.</returns>
2449+
protected virtual Font? GetStateCommonFont()
2450+
{
2451+
try
2452+
{
2453+
// Use null-conditional operators to safely access nested properties
2454+
// This prevents issues during design time serialization when StateCommon might not be fully initialized
2455+
return StateCommon.ComboBox.Content?.Font;
2456+
}
2457+
catch
2458+
{
2459+
// If StateCommon is not fully initialized or there's a serialization issue,
2460+
// return null to fall back to base.Font
2461+
return null;
2462+
}
2463+
}
2464+
2465+
/// <summary>
2466+
/// Sets the font to StateCommon.ComboBox.Content.Font safely, handling design mode serialization issues.
2467+
/// </summary>
2468+
/// <param name="value">The font value to set.</param>
2469+
/// <returns>True if the font was set to StateCommon, false to fall back to base.Font.</returns>
2470+
protected virtual bool SetStateCommonFont(Font? value)
2471+
{
2472+
try
2473+
{
2474+
// Use null-conditional operators to safely access nested properties
2475+
// This prevents issues during design time serialization when StateCommon might not be fully initialized
2476+
if (StateCommon.ComboBox?.Content != null)
2477+
{
2478+
StateCommon.ComboBox.Content.Font = value;
2479+
2480+
return true;
2481+
}
2482+
}
2483+
catch
2484+
{
2485+
// If StateCommon is not fully initialized or there's a serialization issue,
2486+
// return false to fall back to base.Font
2487+
}
2488+
2489+
return false;
2490+
}
2491+
24382492
// ReSharper restore VirtualMemberNeverOverridden.Global
24392493
#endregion
24402494

0 commit comments

Comments
 (0)