-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: KryptonMessageBox Certain length of the first line of text can push the text on the following out of the visible area. #607
Comments
@Smurf-IV Is this something to do with the resizing method? |
Somewhere near that, and probably and AutoSizing message timing thing. |
@giduac What OS are you using, and what DPI settings have you got set for you app (Manifest or program.cs ?) |
@Wagnerp Does the "ST MessageBox example app" do the same as the OP ? |
Hold on, let me check on the latest alpha. |
Windows DPI = 100% The first post including the video was done Win 10. Same result/error there. BTW: I worked around it (for now) by adding two newline chars ( \n\n\ ) to the end of the message text. |
@Smurf-IV Seems that there might be a bug with the following private void UpdateSizing(IWin32Window showOwner)
{
Size messageSizing = UpdateMessageSizing(showOwner);
Size buttonsSizing = UpdateButtonsSizing();
// Size of window is calculated from the client area
ClientSize = new Size(Math.Max(messageSizing.Width, buttonsSizing.Width),
messageSizing.Height + buttonsSizing.Height);
} |
@Smurf-IV Might have found the bug Our version: private Size UpdateMessageSizing(IWin32Window showOwner)
{
// Update size of the message label but with a maximum width
Size textSize;
using (Graphics g = CreateGraphics())
{
// Find size of the label, with a max of 2/3 screen width
Screen screen = showOwner != null ? Screen.FromHandle(showOwner.Handle) : Screen.PrimaryScreen;
SizeF scaledMonitorSize = screen.Bounds.Size;
scaledMonitorSize.Width *= 2 / 3.0f;
scaledMonitorSize.Height *= 0.95f;
_messageText.UpdateFont();
SizeF messageSize = g.MeasureString(_text, _messageText.Font, scaledMonitorSize);
// SKC: Don't forget to add the TextExtra into the calculation
SizeF captionSize = g.MeasureString($@"{_caption} {TextExtra}", _messageText.Font, scaledMonitorSize);
var messageXSize = Math.Max(messageSize.Width, captionSize.Width);
// Work out DPI adjustment factor
messageSize.Width = messageXSize * FactorDpiX;
messageSize.Height *= FactorDpiY;
// Always add on ad extra 5 pixels as sometimes the measure size does not draw the last
// character it contains, this ensures there is always definitely enough space for it all
messageSize.Width += 5;
textSize = Size.Ceiling(messageSize);
}
// Find size of icon area plus the text area added together
if (_messageIcon.Image != null)
{
return new Size(textSize.Width + _messageIcon.Width, Math.Max(_messageIcon.Height + 10, textSize.Height));
}
return textSize;
} Original version: private Size UpdateMessageSizing()
{
// Update size of the message label but with a maximum width
using (Graphics g = CreateGraphics())
{
// Find size of the label when it has a maximum length of 400
_messageText.UpdateFont();
Size messageSize = g.MeasureString(_text, _messageText.Font, 400).ToSize();
// Work out DPI adjustment factor
float factorX = g.DpiX > 96 ? (1.0f * g.DpiX / 96) : 1.0f;
float factorY = g.DpiY > 96 ? (1.0f * g.DpiY / 96) : 1.0f;
messageSize.Width = (int)((float)messageSize.Width * factorX);
messageSize.Height = (int)((float)messageSize.Height * factorY);
// Always add on ad extra 5 pixels as sometimes the measure size does not draw the last
// character it contains, this ensures there is always definitely enough space for it all
messageSize.Width += 5;
_messageText.Size = messageSize;
}
// Resize panel containing the message text
Padding panelMessagePadding = _panelMessageText.Padding;
_panelMessageText.Width = _messageText.Size.Width + panelMessagePadding.Horizontal;
_panelMessageText.Height = _messageText.Size.Height + panelMessagePadding.Vertical;
// Find size of icon area plus the text area added together
Size panelSize = _panelMessageText.Size;
if (_messageIcon.Image != null)
{
panelSize.Width += _panelMessageIcon.Width;
panelSize.Height = Math.Max(panelSize.Height, _panelMessageIcon.Height);
}
// Enforce a minimum size for the message area
panelSize = new Size(Math.Max(_panelMessage.Size.Width, panelSize.Width),
Math.Max(_panelMessage.Size.Height, panelSize.Height));
// Note that the width will be ignored in this update, but that is fine as
// it will be adjusted by the UpdateSizing method that is the caller.
_panelMessage.Size = panelSize;
return panelSize;
} I think the // Enforce a minimum size for the message area
panelSize = new Size(Math.Max(_panelMessage.Size.Width, panelSize.Width),
Math.Max(_panelMessage.Size.Height, panelSize.Height));
// Note that the width will be ignored in this update, but that is fine as
// it will be adjusted by the UpdateSizing method that is the caller.
_panelMessage.Size = panelSize;
return panelSize; |
All that should be replaced by an Auto Sized Table Layout.. |
Edited/updated: 01-27 Hi, In the width calculation the margins are not included.
private Size UpdateMessageSizing(IWin32Window showOwner)
{
// Update size of the message label but with a maximum width
Size textSize;
using (Graphics g = CreateGraphics())
{
// Find size of the label, with a max of 2/3 screen width
Screen screen = showOwner != null ? Screen.FromHandle(showOwner.Handle) : Screen.PrimaryScreen;
SizeF scaledMonitorSize = screen.Bounds.Size;
scaledMonitorSize.Width *= 2 / 3.0f;
scaledMonitorSize.Height *= 0.95f;
_messageText.UpdateFont();
SizeF messageSize = g.MeasureString(_text, _messageText.Font, scaledMonitorSize);
// SKC: Don't forget to add the TextExtra into the calculation
SizeF captionSize = g.MeasureString($@"{_caption} {TextExtra}", _messageText.Font, scaledMonitorSize);
var messageXSize = Math.Max(messageSize.Width, captionSize.Width);
// Work out DPI adjustment factor
var factorX = g.DpiX > 96 ? (1.0f * g.DpiX / 96) : 1.0f;
var factorY = g.DpiY > 96 ? (1.0f * g.DpiY / 96) : 1.0f;
messageSize.Width = messageXSize * factorX;
messageSize.Height *= factorY;
// Always add on ad extra 5 pixels as sometimes the measure size does not draw the last
// character it contains, this ensures there is always definitely enough space for it all
messageSize.Width += 5;
textSize = Size.Ceiling(messageSize);
}
return new Size(
textSize.Width +
_messageIcon.Width +
_messageIcon.Margin.Left +
_messageIcon.Margin.Right +
_messageText.Margin.Left +
_messageText.Margin.Right,
Math.Max(_messageIcon.Height + 10, textSize.Height));
} I tried this and it seems to work with different strings and those that it specifically occurs with. |
Fixed 29/01/2022 |
It looks more like the control that hold the text doesn't resize correctly and text gets caught under the inset/panel that holds the buttons.
Turning the icon on and off influenced this.
So far it occurs only when an icon is displayed
When it occurs a longer caption text will make the text appear again.
Observed in KT:
Stable: 6.2201.4
Nightly 60.22.1.22-alpha
Canary: 60.22.1.23-beta
To reproduce / experiment:
Watch the video
Use the sample program included (toolkit needs to be added because of the upload size).
message-box-text-problem.mp4
KMessageBoxTest.zip
The text was updated successfully, but these errors were encountered: