Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ protected override void OnHandleCreated(EventArgs e)
protected override void WindowChromeStart()
{
// Make sure the views for the buttons are created
if (_recreateButtons)
if (_recreateButtons && this.ControlBox && !string.IsNullOrWhiteSpace(this.Text))
{
_buttonManager.RecreateButtons();
_recreateButtons = false;
Expand Down Expand Up @@ -3322,5 +3322,49 @@ public static bool GetIsInAdministratorMode()

return _isInAdministratorMode;
}
#endregion
#endregion


/// <summary>
/// Determines whether the KryptonForm has usable caption content
/// for non-client painting (Text / TextExtra and chrome-aware).
/// </summary>
protected override bool HasCaptionContent()
{
// No border => no non-client caption at all
if (FormBorderStyle == FormBorderStyle.None)
{
return false;
}

// No visible caption content
bool hasCaptionText =
!string.IsNullOrWhiteSpace(Text) ||
!string.IsNullOrWhiteSpace(TextExtra);

if (!hasCaptionText)
{
return false;
}

// Edge-case:
// When ControlBox is false and caption content is minimal,
// avoid treating the caption as usable to prevent
// non-client artifacts (e.g. white bar on deactivate).
if (!ControlBox && string.IsNullOrWhiteSpace(TextExtra))
{
return false;
}

return FormBorderStyle switch
{
FormBorderStyle.FixedSingle => true,
FormBorderStyle.Fixed3D => true,
FormBorderStyle.FixedDialog => true,
FormBorderStyle.Sizable => true,
FormBorderStyle.FixedToolWindow => true,
FormBorderStyle.SizableToolWindow => true,
_ => false
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,14 @@ protected void InvalidateNonClient(Rectangle invalidRect, bool excludeClientArea
{
hRgn = invalidRegion.GetHrgn(g);

if (!HasCaptionContent())
this.SuspendPaint();

PI.RedrawWindow(Handle, IntPtr.Zero, hRgn.Value,
PI.RDW_FRAME | PI.RDW_UPDATENOW | PI.RDW_INVALIDATE);

if (!HasCaptionContent())
this.ResumePaint();
}
catch (InvalidOperationException ioEx)
{
Expand All @@ -795,10 +801,25 @@ protected void InvalidateNonClient(Rectangle invalidRect, bool excludeClientArea
}
}

/// <summary>
/// Gets rectangle that is the real window rectangle based on Win32 API call.
/// </summary>
protected Rectangle RealWindowRectangle
/// <summary>
/// Determines whether the form has a native non-client frame with a usable caption.
///
/// This method must be overridden by derived classes that provide
/// a concrete implementation of form chrome handling.
/// </summary>
/// <exception cref="NotSupportedException">
/// Thrown when the method is not overridden in a derived class.
/// </exception>
protected virtual bool HasCaptionContent()
{
throw new NotSupportedException(
$"{GetType().Name} must override HasCaptionContent() to provide a valid implementation.");
}

/// <summary>
/// Gets rectangle that is the real window rectangle based on Win32 API call.
/// </summary>
protected Rectangle RealWindowRectangle
{
get
{
Expand Down
96 changes: 81 additions & 15 deletions Source/Krypton Components/TestForm/Bug2914Test.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions Source/Krypton Components/TestForm/Bug2914Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,68 @@ public Bug2914Test()
{
InitializeComponent();
}

private void Bug2914Test_Load(object sender, EventArgs e)
{

}

// Event handler for kryptonButton1 click
// Opens the Bug2914Test form as a modal dialog with no title bar text
// and without the system control buttons (minimize, maximize, close).
private void kryptonButton1_Click(object sender, EventArgs e)
{
// Create a new instance of the Bug2914Test form
Bug2914Test frm = new Bug2914Test();

// Center the form on the screen when it is shown
frm.StartPosition = FormStartPosition.Manual;

// Explicitly set the location (redundant when using CenterScreen,
// but kept for consistency or testing purposes)
frm.Location = new Point(0, 0);

// Remove the window title text
frm.Text = string.Empty;

// Allow the form to be resized
frm.FormBorderStyle = FormBorderStyle.Sizable;

// Disable the control box (Close, Minimize, Maximize buttons)
frm.ControlBox = false;

// Show the form as a modal dialog
frm.ShowDialog();
}

// Event handler for kryptonButton2 click
// Closes the current form.
private void kryptonButton2_Click(object sender, EventArgs e)
{
// Close the current window
this.Close();
}

// Event handler for kryptonButton3 click
// Opens the Bug2914Test form as a modal dialog with a visible title.
private void kryptonButton3_Click(object sender, EventArgs e)
{
// Create a new instance of the Bug2914Test form
Bug2914Test frm = new Bug2914Test();

// Center the form on the screen
frm.StartPosition = FormStartPosition.CenterScreen;

// Set the initial position of the form
frm.Location = new Point(0, 0);

// Set the window title text
frm.Text = "HOLA";

// Allow the form to be resized
frm.FormBorderStyle = FormBorderStyle.Sizable;

// Show the form as a modal dialog
frm.ShowDialog();
}
}
3 changes: 3 additions & 0 deletions Source/Krypton Components/TestForm/Bug2914Test.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="kryptonManager1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
Loading