Skip to content

Commit 6e139d1

Browse files
committed
2304-V100-KryptonForm-border-issues
- PaletteBorder.Rounding adapts return value to the border state. - CommonHelper.GetWindowBorders reverted to the V85 version.
1 parent c2875a3 commit 6e139d1

File tree

3 files changed

+73
-35
lines changed

3 files changed

+73
-35
lines changed

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: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,49 +1226,62 @@ public static void RemoveControlFromParent([DisallowNull] Control? c)
12261226
}
12271227
}
12281228

1229+
1230+
public static Padding GetWindowBorders(CreateParams createParams)
1231+
{
1232+
var rect = new PI.RECT
1233+
{
1234+
// Start with a zero sized rectangle
1235+
left = 0,
1236+
right = 0,
1237+
top = 0,
1238+
bottom = 0
1239+
};
1240+
1241+
// Adjust rectangle to add on the borders required
1242+
PI.AdjustWindowRectEx(ref rect, (uint)createParams.Style, false, createParams.ExStyle);
1243+
1244+
// Return the per side border values
1245+
return new Padding(-rect.left, -rect.top, rect.right, rect.bottom);
1246+
}
1247+
12291248
/// <summary>
12301249
/// Gets the size of the borders requested by the real window.
12311250
/// </summary>
1232-
/// <param name="cp">Window style parameters.</param>
1251+
/// <param name="createParams">Window style parameters.</param>
12331252
/// <param name="form">Optional VisualForm base to detect usage of Chrome drawing</param>
12341253
/// <returns>Border sizing.</returns>
1235-
public static Padding GetWindowBorders(CreateParams cp, KryptonForm form)
1254+
public static Padding GetWindowBorders2(CreateParams createParams, KryptonForm form)
12361255
{
1237-
int xOffset = 0;
1238-
int yOffset = 0;
1239-
uint dwStyle = (uint)cp.Style;
1240-
bool useAdjust = false;
1241-
1242-
if (form.StateCommon is {Border: PaletteFormBorder formBorder })
1256+
if (form.StateCommon?.Border is PaletteFormBorder formBorder)
12431257
{
1244-
useAdjust = true;
1258+
int xOffset = 0;
1259+
int yOffset = 0;
1260+
12451261
var (xOffset1, yOffset1) = formBorder.BorderWidths(form.FormBorderStyle);
12461262

12471263
xOffset = Math.Max(0, xOffset1);
12481264
yOffset = Math.Max(0, yOffset1);
1249-
}
12501265

1251-
var rect = new PI.RECT
1252-
{
1253-
// Start with a zero sized rectangle
1254-
top = -yOffset,
1255-
bottom = yOffset
1256-
};
1266+
var rect = new PI.RECT
1267+
{
1268+
// Start with a zero sized rectangle
1269+
top = -yOffset,
1270+
bottom = yOffset
1271+
};
12571272

1258-
if (useAdjust)
1259-
{
12601273
// Adjust rectangle to add on the borders required
1261-
PI.AdjustWindowRectEx(ref rect, dwStyle, false, cp.ExStyle);
1262-
PaletteBase? resolvedPalette = form.GetResolvedPalette();
1263-
if (resolvedPalette == null)
1274+
PI.AdjustWindowRectEx(ref rect, (uint)createParams.Style, false, createParams.ExStyle);
1275+
1276+
if (form.GetResolvedPalette() is null)
12641277
{
12651278
// Need to breakout when the form is closing
12661279
return new Padding(-rect.left, -rect.top, rect.right, rect.bottom);
12671280
}
12681281

1269-
if (!CommonHelper.IsFormMaximized(form))
1282+
if (!CommonHelper.IsFormMaximized(form) && form.StateCommon.Border.Width > 0)
12701283
{
1271-
switch (form.StateCommon!.Border.GetBorderDrawBorders(PaletteState.Normal))
1284+
switch (formBorder.GetBorderDrawBorders(PaletteState.Normal))
12721285
{
12731286
case PaletteDrawBorders.None:
12741287
rect.left = 0;
@@ -1316,17 +1329,22 @@ public static Padding GetWindowBorders(CreateParams cp, KryptonForm form)
13161329
else if (form.IsMdiChild)
13171330
{
13181331
rect.top = 0;
1332+
rect.left = 0;
1333+
rect.right = 0;
13191334
rect.bottom = 0;
13201335
}
13211336
else
13221337
{
13231338
rect.bottom -= yOffset;
13241339
rect.top -= rect.bottom;
13251340
}
1326-
}
13271341

1328-
// Return the per side border values
1329-
return new Padding(-rect.left, -rect.top, rect.right, rect.bottom);
1342+
return new Padding(-rect.left, -rect.top, rect.right, rect.bottom);
1343+
}
1344+
else
1345+
{
1346+
throw new NullReferenceException("form.StateCommon cannot be null.");
1347+
}
13301348
}
13311349

13321350
/// <summary>

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
{

0 commit comments

Comments
 (0)