Skip to content
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

Closed
giduac opened this issue Jan 23, 2022 · 13 comments
Labels
bug Something isn't working fixed This issue has been fixed.
Milestone

Comments

@giduac
Copy link
Contributor

giduac commented Jan 23, 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

@giduac giduac added the bug Something isn't working label Jan 23, 2022
@PWagner1
Copy link
Contributor

@Smurf-IV Is this something to do with the resizing method?

@Smurf-IV
Copy link
Member

@Smurf-IV Is this something to do with the resizing method?

Somewhere near that, and probably and AutoSizing message timing thing.

@Smurf-IV
Copy link
Member

@giduac What OS are you using, and what DPI settings have you got set for you app (Manifest or program.cs ?)

@Smurf-IV
Copy link
Member

@Wagnerp Does the "ST MessageBox example app" do the same as the OP ?

@PWagner1
Copy link
Contributor

@Wagnerp Does the "ST MessageBox example app" do the same as the OP ?

Hold on, let me check on the latest alpha.

@PWagner1
Copy link
Contributor

@Smurf-IV & @giduac Yes it does, but then something unusual happens. Watch until the end.

Animation

@giduac
Copy link
Contributor Author

giduac commented Jan 24, 2022

@giduac What OS are you using, and what DPI settings have you got set for you app (Manifest or program.cs ?)
@Smurf-IV

Windows DPI = 100%
No application specific (like in the test prog) DPI setting.

The first post including the video was done Win 10.
Just tested it on Win7 SP1/ Win 8.1 / Win11 (system dpi 100% on all tests)

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.

@PWagner1
Copy link
Contributor

PWagner1 commented Jan 25, 2022

@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);
        }

@PWagner1
Copy link
Contributor

@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 panelSize could be the issue:

           // 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;

@Smurf-IV
Copy link
Member

All that should be replaced by an Auto Sized Table Layout..
Seems like the things are having an argument as to who is in charge of the sizing.

@giduac
Copy link
Contributor Author

giduac commented Jan 26, 2022

@Wagnerp @Smurf-IV

Edited/updated: 01-27

Hi,

In the width calculation the margins are not included.
Currently the PictureBox has a Left of 8 and right of 4. The wraplabel a left of 4. Which leaves out 16px.
EDIT:

  • Also the if (_messageIcon.Image != null) check is not needed. Since it doesn't matter if the Picturebox has an image assigned or not. Because the cell is Autosized.
  • So the returned Size can be unconditional
        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.
You might give this a try and have a look for yourselves

@PWagner1
Copy link
Contributor

@giduac & @Smurf-IV Will implement today

PWagner1 added a commit that referenced this issue Jan 28, 2022
Smurf-IV added a commit that referenced this issue Jan 29, 2022
@PWagner1 PWagner1 added the fixed This issue has been fixed. label Jan 29, 2022
@PWagner1 PWagner1 added this to the April 2022 milestone Jan 29, 2022
@PWagner1
Copy link
Contributor

Fixed 29/01/2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed This issue has been fixed.
Projects
None yet
Development

No branches or pull requests

3 participants