Skip to content

Commit 44bfa3c

Browse files
committed
* White bar is shown in a KryptonForm Sizable without buttons and text
* Resolved #2914
1 parent 5711af1 commit 44bfa3c

File tree

6 files changed

+265
-5
lines changed

6 files changed

+265
-5
lines changed

Documents/Changelog/Changelog.md

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

55
## 2026-11-xx - Build 2611 (V110 Nightly) - November 2026
66

7+
* Resolved [#2914](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2914), White bar is shown in a `KryptonForm` Sizable without buttons and text
78
* Resolved [#2862](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2862), Form border resize flicker
89
* Implemented [#595](https://github.com/Krypton-Suite/Standard-Toolkit/issues/595), Detachable Ribbons - Added ability to detach `KryptonRibbon` into a floating window with `AllowDetach` property, `Detach()` and `Reattach()` methods, and `RibbonDetached`/`RibbonReattached` events. See [Detachable Ribbons Documentation](Detachable-Ribbons-Feature.md) for comprehensive details.
910
* Implemented [#2898](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2898), `KryptonHScrollBar` & `KryptonVScrollBar` - Part of #2658

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

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,38 @@ protected override bool WindowChromeLeftMouseDown(Point windowPoint)
21932193
return ret;
21942194
}
21952195

2196+
/// <inheritdoc />
2197+
protected override bool OnWM_NCCALCSIZE(ref Message m)
2198+
{
2199+
// Does the LParam contain a RECT or an NCCALCSIZE_PARAMS
2200+
if (m.WParam != IntPtr.Zero)
2201+
{
2202+
// Get the border sizing needed around the client area
2203+
Padding borders = RealWindowBorders;
2204+
2205+
// If caption should be hidden, set top border to 0 to prevent white band
2206+
if (ShouldHideCaption())
2207+
{
2208+
borders = new Padding(borders.Left, 0, borders.Right, borders.Bottom);
2209+
}
2210+
2211+
// Extract the Win32 NCCALCSIZE_PARAMS structure from LPARAM
2212+
PI.NCCALCSIZE_PARAMS calcsize = (PI.NCCALCSIZE_PARAMS)m.GetLParam(typeof(PI.NCCALCSIZE_PARAMS))!;
2213+
2214+
// Reduce provided RECT by the borders
2215+
calcsize.rectProposed.left += borders.Left;
2216+
calcsize.rectProposed.top += borders.Top;
2217+
calcsize.rectProposed.right -= borders.Right;
2218+
calcsize.rectProposed.bottom -= borders.Bottom;
2219+
2220+
// Put back the modified structure
2221+
Marshal.StructureToPtr(calcsize, m.LParam, false);
2222+
}
2223+
2224+
// Message processed, do not pass onto base class for processing
2225+
return true;
2226+
}
2227+
21962228
protected override void OnMove(EventArgs e)
21972229
{
21982230
base.OnMove(e);
@@ -2260,6 +2292,30 @@ private void OnFormBorderStyleChanged()
22602292
return null;
22612293
}
22622294

2295+
/// <summary>
2296+
/// Determines if the caption area should be hidden (no text, no icon, no control box, no visible buttons).
2297+
/// </summary>
2298+
/// <returns>True if caption should be hidden; otherwise false.</returns>
2299+
private bool ShouldHideCaption()
2300+
{
2301+
// Check if there are any visible buttons
2302+
bool hasVisibleButtons = false;
2303+
foreach (ButtonSpecView bsv in _buttonManager.ButtonSpecViews)
2304+
{
2305+
if (bsv.ViewCenter.Visible && bsv.ViewButton.Enabled)
2306+
{
2307+
hasVisibleButtons = true;
2308+
break;
2309+
}
2310+
}
2311+
2312+
// Hide caption if no control box, no text, no icon, and no visible buttons
2313+
return !ControlBox
2314+
&& string.IsNullOrEmpty(GetShortText())
2315+
&& GetDefinedIcon() == null
2316+
&& !hasVisibleButtons;
2317+
}
2318+
22632319
private void SetHeaderStyle(ViewDrawDocker drawDocker,
22642320
PaletteTripleMetricRedirect palette,
22652321
HeaderStyle style)
@@ -2369,15 +2425,29 @@ private bool CheckViewLayout()
23692425
}
23702426

23712427
// Update the heading to enforce a fixed Material-like caption height when Material renderer is active
2372-
if (Renderer is RenderMaterial)
2428+
bool shouldHideCaption = ShouldHideCaption();
2429+
2430+
if (shouldHideCaption)
23732431
{
2374-
const int materialCaptionHeight = 44; // px
2375-
_headingFixedSize.FixedSize = new Size(materialCaptionHeight, materialCaptionHeight);
2432+
// Hide the caption area when there's nothing to display
2433+
_headingFixedSize.FixedSize = Size.Empty;
2434+
_headingFixedSize.Visible = false;
23762435
}
23772436
else
23782437
{
2379-
Padding windowBorders = RealWindowBorders;
2380-
_headingFixedSize.FixedSize = new Size(windowBorders.Top, windowBorders.Top);
2438+
// Ensure the heading is visible
2439+
_headingFixedSize.Visible = true;
2440+
2441+
if (Renderer is RenderMaterial)
2442+
{
2443+
const int materialCaptionHeight = 44; // px
2444+
_headingFixedSize.FixedSize = new Size(materialCaptionHeight, materialCaptionHeight);
2445+
}
2446+
else
2447+
{
2448+
Padding windowBorders = RealWindowBorders;
2449+
_headingFixedSize.FixedSize = new Size(windowBorders.Top, windowBorders.Top);
2450+
}
23812451
}
23822452

23832453
// A change in window state since last time requires a layout

Source/Krypton Components/TestForm/Bug2914Test.Designer.cs

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace TestForm;
12+
13+
public partial class Bug2914Test : KryptonForm
14+
{
15+
public Bug2914Test()
16+
{
17+
InitializeComponent();
18+
}
19+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
</root>

Source/Krypton Components/TestForm/StartScreen.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private void AddButtons()
6161
CreateButton("Accessibility Test (UIA Providers)", "Comprehensive demo and test for UIA Provider implementation (Issue #762). Tests all 10 controls with accessibility support, organized by category with detailed results.", typeof(AccessibilityTest));
6262
CreateButton("Badge Test", "Comprehensive badge functionality demonstration for KryptonButton and KryptonCheckButton.", typeof(ButtonBadgeTest));
6363
CreateButton("Buttons Test", "All the buttons you want to test.", typeof(ButtonsTest));
64+
CreateButton("Bug 2914 Test", "Tests the fix for 2914.", typeof(Bug2914Test));
6465
CreateButton("BugReportingTool", "Easily report bugs with this tool.", typeof(BugReportingDialogTest));
6566
CreateButton("Code Editor", "Native code editor with syntax highlighting, line numbering, code folding, and auto-completion.", typeof(CodeEditorTest));
6667
CreateButton("Countdown Button", "Comprehensive demonstration of KryptonCountdownButton features with customizable duration, format, and enable-at-zero options.", typeof(CountdownButtonTest));

0 commit comments

Comments
 (0)