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

Fix high Dpi, close #3347 #3348

Merged
merged 2 commits into from
Dec 15, 2024

Conversation

CreateAndInject
Copy link
Contributor

100%
image

125%
image

150%
image

175%
image

200%
image

@siegfriedpammer
Copy link
Member

To me it looks like there are some lines/parts missing if scaling is <200%... Is this something you could fix as well?

@christophwille
Copy link
Member

I know that might be out of scope for this PR - what-if we modernized the whole dialog to a Textbox with Scrollbars?

@CreateAndInject
Copy link
Contributor Author

CreateAndInject commented Dec 9, 2024

To me it looks like there are some lines/parts missing if scaling is <200%... Is this something you could fix as well?

@siegfriedpammer I move CustomDialog.cs to a new project, test without any changes, this issue doesn't happen on .NET Framework, only happen on .NET Core(even if I use 1920*1080 100%)

So there's no such issue when ILSpy make the code first time, it's exposed when ILSpy migrate to .NET Core.

My test code: Test.zip

        [STAThread]
        static void Main()
        {
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
            string message = @"Test

   at ICSharpCode.ILSpy.OpenCommand.OnExecute(Object sender, ExecutedRoutedEventArgs e) in E:\Src\ILSpy\ILSpy\Commands\OpenCommand.cs:line 45
   at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at System.Windows.Input.CommandManager.HandleCommandBinding(Object sender, RoutedEventArgs e, CommandBinding commandBinding, Boolean execute)
   at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
   at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandler...";
            string[] buttonTexts = { "Throw", "Debug", "Ignore", "Ignore All" };
            Application.Run(new ICSharpCode.ILSpy.Controls.CustomDialog("Assertion Failed", message, 0, 0, buttonTexts));
        }

@ElektroKill
Copy link
Contributor

I'd think the best way to address this problem would be to let WPF layout engine handle the placement of controls by using a Grid or some panel in which the controls are placed and then let WPF do the rest of the magic. Perhaps the CustomDialog could also be migrated to be defined in .xaml?

Moving it to .xaml would also allow the design to be previewed and easily updated

@CreateAndInject
Copy link
Contributor Author

CreateAndInject commented Dec 13, 2024

I'd think the best way to address this problem would be to let WPF layout engine handle the placement of controls by using a Grid or some panel in which the controls are placed and then let WPF do the rest of the magic. Perhaps the CustomDialog could also be migrated to be defined in .xaml?

Moving it to .xaml would also allow the design to be previewed and easily updated

I want to know, why this code has such issue on .NET Core when Label.Size = MeasureString's result? There's bug on MeasureString on .NET Core? Can you test it and report to Microsft if it's buggy.

@CreateAndInject
Copy link
Contributor Author

I got part of the truth:
This is not .NET Core issue, the reason .NET Core and .NET Framework have different result is because they have different font by default, if we use the same font family and size, .NET Core and .NET Framework have the exact same effect.
Seems the issue is from MeasureString, all of you can test different font family and size, sometimes there's enough space, sometimes there miss a line, and sometimes miss half a line.

                label.Font = new Font(...);
                SizeF size = g.MeasureString(message, label.Font);

@CreateAndInject
Copy link
Contributor Author

@siegfriedpammer I got the whole truth: We should use TextRenderer.MeasureText instead of Graphics.MeasureString to get exact result.

100%
image

125%
image

150%
image

175%
image

200%
image

@siegfriedpammer siegfriedpammer merged commit 51aac5f into icsharpcode:master Dec 15, 2024
5 checks passed
@siegfriedpammer
Copy link
Member

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants