Skip to content

Commit 0060627

Browse files
authored
2304-V100-krypton-form-border-issues (#2610)
* 2304-V100-KryptonForm-border-issues - CommonHelper.GetWindowBorders reverted to the V85 version. - Remove old GetWindowBorders from CommonHelper.cs - Fixes shrinking and growing window sizes - PaletteBorder.Rounding adapts return value to the border state. - Fixes PaletteFormBorder.BorderWidth method - PaletteFormBorder.GetBorderRounding now returns 0 when Rouding is -1 - Fixes CommonHelper.GetWindowBorders - Corrects titlebar system buttonspecs padding on all base themes - Change Padding _metricPaddingHeaderForm to new Padding(3, 0, 0, 0) to allow space between buttonspecs - Restore InternalPanel being browsable - Some housekeeping
1 parent 865c682 commit 0060627

File tree

39 files changed

+121
-315
lines changed

39 files changed

+121
-315
lines changed

Documents/Changelog/Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
====
44

5-
## 2025-11-11 - Build 2511 (V100 RTM) - November 2025
5+
## 2025-11-30 - Build 2511 (V100 RTM) - November 2025
66

7+
* Resolved [#2307](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2304), `KryptonForm` border issues. See issue for details as this solves several tickets connected to this one.
78
* Resolved [#2593](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2593), Scrolling over `KryptonForm` results in OverflowException in `KryptonSystemMenuListener`
89
* Resolved [#2542](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2542), `KryptonForm` cannot be resized by dragging upper corners.
910
* Implemented [#2575](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2575), **[Breaking Change]** `CommonHelper.DesignMode()` behaviour changed, see issue for details.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ public void SetInheritedControlOverride()
818818
/// <summary>
819819
/// Access to the Internal KryptonPanel.
820820
/// </summary>
821-
[Browsable(false)]
821+
[Browsable(true)]
822+
[EditorBrowsable(EditorBrowsableState.Always)]
822823
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
823824
public KryptonPanel InternalPanel => _internalKryptonPanel;
824825

Source/Krypton Components/Krypton.Toolkit/Controls Visuals/VisualForm.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ internal void SendSysCommand(PI.SC_ sysCommand, IntPtr lParam) =>
516516
[Browsable(false)]
517517
[EditorBrowsable(EditorBrowsableState.Never)]
518518
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
519-
public Padding RealWindowBorders => CommonHelper.GetWindowBorders(CreateParams, this as KryptonForm);
519+
public Padding RealWindowBorders => CommonHelper.GetWindowBorders(CreateParams);
520520

521521
/// <summary>
522522
/// Gets a count of the number of paints that have occurred.
@@ -678,8 +678,7 @@ protected Point ScreenToWindow(Point screenPt)
678678
/// </summary>
679679
/// <param name="invalidRect">Area to invalidate.</param>
680680
/// <param name="excludeClientArea">Should client area be excluded.</param>
681-
protected void InvalidateNonClient(Rectangle invalidRect,
682-
bool excludeClientArea)
681+
protected void InvalidateNonClient(Rectangle invalidRect, bool excludeClientArea)
683682
{
684683
if (IsDisposed || Disposing || !IsHandleCreated)
685684
{
@@ -692,7 +691,7 @@ protected void InvalidateNonClient(Rectangle invalidRect,
692691
{
693692
Padding realWindowBorders = RealWindowBorders;
694693
Rectangle realWindowRectangle = RealWindowRectangle;
695-
694+
696695
invalidRect = realWindowRectangle with
697696
{
698697
X = -realWindowBorders.Left,
@@ -744,7 +743,7 @@ protected Rectangle RealWindowRectangle
744743
// Create rectangle that encloses the entire window
745744
return new Rectangle(0, 0,
746745
windowRect.right - windowRect.left,
747-
windowRect.bottom - windowRect.top);
746+
windowRect.bottom - windowRect.top);
748747
}
749748
}
750749
#endregion
@@ -998,7 +997,6 @@ protected virtual void OnNeedPaint(object? sender, [DisallowNull] NeedLayoutEven
998997
{
999998
NeedLayout = true;
1000999
}
1001-
10021000
InvalidateNonClient();
10031001
}
10041002

@@ -1488,7 +1486,6 @@ protected virtual void OnNonClientPaint(IntPtr hWnd)
14881486
{
14891487
// Create rectangle that encloses the entire window
14901488
Rectangle windowBounds = RealWindowRectangle;
1491-
14921489
// We can only draw a window that has some size
14931490
if (windowBounds is { Width: > 0, Height: > 0 })
14941491
{

Source/Krypton Components/Krypton.Toolkit/General/CommonHelper.cs

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,102 +1226,20 @@ public static void RemoveControlFromParent([DisallowNull] Control? c)
12261226
}
12271227
}
12281228

1229-
/// <summary>
1230-
/// Gets the size of the borders requested by the real window.
1231-
/// </summary>
1232-
/// <param name="cp">Window style parameters.</param>
1233-
/// <param name="form">Optional VisualForm base to detect usage of Chrome drawing</param>
1234-
/// <returns>Border sizing.</returns>
1235-
public static Padding GetWindowBorders(CreateParams cp, KryptonForm? form)
1236-
{
1237-
int xOffset = 0;
1238-
int yOffset = 0;
1239-
uint dwStyle = (uint)cp.Style;
1240-
bool useAdjust = false;
1241-
if (form is { StateCommon.Border: PaletteFormBorder formBorder } kryptonForm)
1242-
{
1243-
useAdjust = true;
1244-
var (xOffset1, yOffset1) = formBorder.BorderWidths(kryptonForm.FormBorderStyle);
1245-
xOffset = Math.Max(0, xOffset1);
1246-
yOffset = Math.Max(0, yOffset1);
1247-
}
12481229

1230+
public static Padding GetWindowBorders(CreateParams createParams)
1231+
{
12491232
var rect = new PI.RECT
12501233
{
12511234
// Start with a zero sized rectangle
1252-
top = -yOffset,
1253-
bottom = yOffset
1235+
left = 0,
1236+
right = 0,
1237+
top = 0,
1238+
bottom = 0
12541239
};
1255-
if (useAdjust)
1256-
{
1257-
// Adjust rectangle to add on the borders required
1258-
PI.AdjustWindowRectEx(ref rect, dwStyle, false, cp.ExStyle);
1259-
PaletteBase? resolvedPalette = form?.GetResolvedPalette();
1260-
if (resolvedPalette == null)
1261-
{
1262-
// Need to breakout when the form is closing
1263-
return new Padding(-rect.left, -rect.top, rect.right, rect.bottom);
1264-
}
1265-
1266-
if (!CommonHelper.IsFormMaximized(form!))
1267-
{
1268-
// Set the values determined by the formBorder.BorderWidths etc.
1269-
rect.left = -xOffset;
1270-
rect.right = xOffset;
1271-
rect.bottom = yOffset;
12721240

1273-
switch (form!.StateCommon!.Border.GetBorderDrawBorders(PaletteState.Normal))
1274-
{
1275-
case PaletteDrawBorders.None:
1276-
rect.left = 0;
1277-
rect.right = 0;
1278-
rect.bottom = 0;
1279-
break;
1280-
case PaletteDrawBorders.Bottom:
1281-
case PaletteDrawBorders.TopBottom:
1282-
rect.left = 0;
1283-
rect.right = 0;
1284-
break;
1285-
case PaletteDrawBorders.Left:
1286-
case PaletteDrawBorders.TopLeft:
1287-
rect.right = 0;
1288-
rect.bottom = 0;
1289-
break;
1290-
case PaletteDrawBorders.BottomLeft:
1291-
case PaletteDrawBorders.TopBottomLeft:
1292-
rect.right = 0;
1293-
break;
1294-
case PaletteDrawBorders.Right:
1295-
case PaletteDrawBorders.TopRight:
1296-
rect.left = 0;
1297-
rect.bottom = 0;
1298-
break;
1299-
case PaletteDrawBorders.BottomRight:
1300-
case PaletteDrawBorders.TopBottomRight:
1301-
rect.left = 0;
1302-
break;
1303-
case PaletteDrawBorders.LeftRight:
1304-
case PaletteDrawBorders.TopLeftRight:
1305-
rect.bottom = 0;
1306-
break;
1307-
//case PaletteDrawBorders.Inherit:
1308-
//case PaletteDrawBorders.BottomLeftRight:
1309-
//case PaletteDrawBorders.All:
1310-
default:
1311-
break;
1312-
}
1313-
}
1314-
else if (form?.IsMdiChild ?? false)
1315-
{
1316-
rect.top = 0;
1317-
rect.bottom = 0;
1318-
}
1319-
else
1320-
{
1321-
rect.bottom -= yOffset;
1322-
rect.top -= rect.bottom;
1323-
}
1324-
}
1241+
// Adjust rectangle to add on the borders required
1242+
PI.AdjustWindowRectEx(ref rect, (uint)createParams.Style, false, createParams.ExStyle);
13251243

13261244
// Return the per side border values
13271245
return new Padding(-rect.left, -rect.top, rect.right, rect.bottom);

Source/Krypton Components/Krypton.Toolkit/Palette Base/PaletteBorder/PaletteBorder.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,19 @@ public virtual int Width
594594
/// </summary>
595595
/// <param name="state">Palette value should be applicable to this state.</param>
596596
/// <returns>Border width.</returns>
597-
public int GetBorderWidth(PaletteState state) => Width != -1 ? Width : _inherit.GetBorderWidth(state);
597+
//public int GetBorderWidth(PaletteState state) => Width != -1 ? Width : _inherit.GetBorderWidth(state);
598+
public int GetBorderWidth(PaletteState state)
599+
{
600+
if (Width > 0)
601+
{
602+
return Width;
603+
}
604+
else
605+
{
606+
int width = _inherit.GetBorderWidth(state);
607+
return width > 0 ? width : 0;
608+
}
609+
}
598610
#endregion
599611

600612
#region Rounding
@@ -608,7 +620,18 @@ public virtual int Width
608620
[RefreshProperties(RefreshProperties.All)]
609621
public float Rounding
610622
{
611-
get => _storage?.BorderRounding ?? GlobalStaticValues.DEFAULT_PRIMARY_CORNER_ROUNDING_VALUE;
623+
get
624+
{
625+
if (_storage is not null
626+
&& _storage.BorderRounding > 0
627+
&& Draw != InheritBool.False
628+
&& DrawBorders != PaletteDrawBorders.None)
629+
{
630+
return _storage.BorderRounding;
631+
}
632+
633+
return GlobalStaticValues.DEFAULT_PRIMARY_CORNER_ROUNDING_VALUE;
634+
}
612635

613636
set
614637
{

Source/Krypton Components/Krypton.Toolkit/Palette Base/PaletteBorder/PaletteFormBorder.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public PaletteFormBorder([DisallowNull] IPaletteBorder inherit,
3434

3535
#region Width
3636
internal bool UseThemeFormChromeBorderWidth { get; set; } = true;
37-
private FormBorderStyle _lastFormFormBorderStyle = FormBorderStyle.Sizable;
3837

3938
/// <summary>
4039
/// Gets and sets the border width.
@@ -73,7 +72,7 @@ public override int Width
7372
/// <returns>Border rounding.</returns>
7473
public override float GetBorderRounding(PaletteState state)
7574
{
76-
if (Draw == InheritBool.False)
75+
if (Draw == InheritBool.False || Rounding == -1F)
7776
{
7877
return 0;
7978
}
@@ -86,12 +85,11 @@ public override float GetBorderRounding(PaletteState state)
8685
/// </summary>
8786
[KryptonPersist(false)]
8887
[Browsable(false)]
89-
[EditorBrowsable(EditorBrowsableState.Never)]
9088
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
9189
[DefaultValue(PaletteGraphicsHint.None)]
9290
public override PaletteGraphicsHint GraphicsHint
9391
{
94-
// #1757
92+
// #1757: Make sure that the little transparency elements on the curves do not show up for Form Borders
9593
get => PaletteGraphicsHint.None;
9694

9795
set
@@ -110,55 +108,49 @@ public override PaletteGraphicsHint GetBorderGraphicsHint(PaletteState state)
110108
/// https://github.com/Krypton-Suite/Standard-Toolkit/issues/139
111109
internal (int xBorder, int yBorder) BorderWidths(FormBorderStyle formFormBorderStyle)
112110
{
113-
var xBorder = base.Width; // do not call GetBorderWidth(PaletteState.Normal); as it will get lost in the stack recursion !
114-
var yBorder = base.Width;
115-
if (Draw == InheritBool.False)
111+
int xBorder;
112+
int yBorder;
113+
114+
if (UseThemeFormChromeBorderWidth)
116115
{
117116
xBorder = 0;
118117
yBorder = 0;
119118
}
120-
else if (!UseThemeFormChromeBorderWidth)
119+
else
121120
{
122-
_lastFormFormBorderStyle = formFormBorderStyle;
123121
switch (formFormBorderStyle)
124122
{
125123
case FormBorderStyle.None:
126124
xBorder = 0;
127125
yBorder = 0;
128126
break;
127+
129128
case FormBorderStyle.FixedSingle:
130129
case FormBorderStyle.FixedToolWindow:
131130
xBorder = PI.GetSystemMetrics(PI.SM_.CXFIXEDFRAME);
132131
yBorder = PI.GetSystemMetrics(PI.SM_.CYFIXEDFRAME);
133132
break;
133+
134134
case FormBorderStyle.Fixed3D:
135135
xBorder = PI.GetSystemMetrics(PI.SM_.CXEDGE);
136136
yBorder = PI.GetSystemMetrics(PI.SM_.CYEDGE);
137137
break;
138+
138139
case FormBorderStyle.FixedDialog:
139140
xBorder = PI.GetSystemMetrics(PI.SM_.CXDLGFRAME);
140141
yBorder = PI.GetSystemMetrics(PI.SM_.CYDLGFRAME);
141142
break;
143+
142144
case FormBorderStyle.Sizable:
143145
case FormBorderStyle.SizableToolWindow:
144146
xBorder = PI.GetSystemMetrics(PI.SM_.CXSIZEFRAME);
145147
yBorder = PI.GetSystemMetrics(PI.SM_.CYSIZEFRAME);
146148
break;
149+
147150
default:
148151
throw new ArgumentOutOfRangeException(nameof(formFormBorderStyle), formFormBorderStyle, null);
149152
}
150153
}
151-
else if (xBorder == -1)
152-
{
153-
var rect = new PI.RECT
154-
{
155-
// Start with a zero sized rectangle
156-
};
157-
// Adjust rectangle to add on the borders required
158-
PI.AdjustWindowRect(ref rect, PI.WS_.SIZEFRAME, false);
159-
xBorder = -rect.left;
160-
yBorder = rect.bottom;
161-
}
162154

163155
return (xBorder, yBorder);
164156
}

Source/Krypton Components/Krypton.Toolkit/Palette Builtin/Material/Bases/PaletteMaterialBase.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,7 @@ public override Padding GetMetricPadding(KryptonForm? owningForm, PaletteState s
328328
switch (metric)
329329
{
330330
case PaletteMetricPadding.HeaderButtonPaddingForm:
331-
if (owningForm == null)
332-
{
333-
return new Padding();
334-
}
335-
return new Padding(0, owningForm!.RealWindowBorders.Right, 0, 0);
331+
return new Padding(0);
336332
case PaletteMetricPadding.PageButtonPadding:
337333
return _metricPaddingPageButtons;
338334
case PaletteMetricPadding.BarPaddingTabs:

Source/Krypton Components/Krypton.Toolkit/Palette Builtin/Microsoft 365/Bases/PaletteMicrosoft365Base.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static PaletteMicrosoft365Base()
100100
private static readonly Padding _metricPaddingRibbon = new Padding(0, 1, 1, 1);
101101
private static readonly Padding _metricPaddingRibbonAppButton = new Padding(3, 0, 3, 0);
102102
private static readonly Padding _metricPaddingHeader = new Padding(0, 3, 1, 3);
103-
//private static readonly Padding _metricPaddingHeaderForm = new Padding(0, owningForm!.RealWindowBorders.Right, 0, 0);//, 3, 0, -3); // Move the Maximised Form buttons down a bit
103+
private static readonly Padding _metricPaddingHeaderForm = new Padding(3, 0, 0, 0);
104104
private static readonly Padding _metricPaddingInputControl = new Padding(0, 1, 0, 1);
105105
private static readonly Padding _metricPaddingBarInside = new Padding(3);
106106
private static readonly Padding _metricPaddingBarTabs = new Padding(0);
@@ -3153,11 +3153,7 @@ public override Padding GetMetricPadding(KryptonForm? owningForm, PaletteState s
31533153
case PaletteMetricPadding.BarPaddingOutside:
31543154
return _metricPaddingBarOutside;
31553155
case PaletteMetricPadding.HeaderButtonPaddingForm:
3156-
if (owningForm == null)
3157-
{
3158-
return new Padding();
3159-
}
3160-
return new Padding(0, owningForm!.RealWindowBorders.Right, 0, 0);
3156+
return _metricPaddingHeaderForm;
31613157
case PaletteMetricPadding.RibbonButtonPadding:
31623158
return _metricPaddingRibbon;
31633159
case PaletteMetricPadding.RibbonAppButton:

Source/Krypton Components/Krypton.Toolkit/Palette Builtin/Microsoft 365/Extra Themes/Bases/PaletteMicrosoft365BlackDarkModeAlternateBase.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static PaletteMicrosoft365BlackDarkModeAlternateBase()
9696
private static readonly Padding _metricPaddingRibbon = new Padding(0, 1, 1, 1);
9797
private static readonly Padding _metricPaddingRibbonAppButton = new Padding(3, 0, 3, 0);
9898
private static readonly Padding _metricPaddingHeader = new Padding(0, 3, 1, 3);
99-
//private static readonly Padding _metricPaddingHeaderForm = new Padding(0, owningForm!.RealWindowBorders.Right, 0, 0);//, 3, 0, -3); // Move the Maximised Form buttons down a bit
99+
private static readonly Padding _metricPaddingHeaderForm = new Padding(3, 0, 0, 0);
100100
private static readonly Padding _metricPaddingInputControl = new Padding(0, 1, 0, 1);
101101
private static readonly Padding _metricPaddingBarInside = new Padding(3);
102102
private static readonly Padding _metricPaddingBarTabs = new Padding(0);
@@ -3089,11 +3089,7 @@ public override Padding GetMetricPadding(KryptonForm? owningForm, PaletteState s
30893089
case PaletteMetricPadding.BarPaddingOutside:
30903090
return _metricPaddingBarOutside;
30913091
case PaletteMetricPadding.HeaderButtonPaddingForm:
3092-
if (owningForm == null)
3093-
{
3094-
return new Padding();
3095-
}
3096-
return new Padding(0, owningForm!.RealWindowBorders.Right, 0, 0);
3092+
return _metricPaddingHeaderForm;
30973093
case PaletteMetricPadding.RibbonButtonPadding:
30983094
return _metricPaddingRibbon;
30993095
case PaletteMetricPadding.RibbonAppButton:

0 commit comments

Comments
 (0)