Skip to content

Update Form's Minimum and Maximum sizes with DPI_CHANGED event #7467

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

Merged
merged 8 commits into from
Aug 12, 2022

Conversation

dreddy-work
Copy link
Member

@dreddy-work dreddy-work commented Jul 20, 2022

Description:

Currently, Form's MinimumSize and MaximumSize are not updated when a DPI_CHNAGED event received by the Form. This prevents scaling of Form to match with the Dpi when its minimum or maximum size properties are set. Users trying to work around this issue may see problems like #7251.

Creating this draft PR to assess the risk for .NET 7.0.

Change in behavior:

Application running in PermonitorV2 mode will see following behavioral change when application moved from one monitor to the other that have different Dpi/Scaling settings and Form has either Minimum and/or Maximum size property set.

  • Minimum and Maximum size of the Form will be changed and any runtime dependency on these might be impacted.
  • Raising MinimumSizeChnaged and/or MaximumSizeChnaged events that were not before.
  • Scaled Form size now have new constraint values for Minimum and Maximum sizes.

Before fix: ( moving from 100% to 300%)
GetImage (2)

GetImage (3)

After fix:
GetImage
GetImage (1)

Microsoft Reviewers: Open in CodeFlow

fixes #7251
fixes #7535

@ghost ghost assigned dreddy-work Jul 20, 2022
@ghost ghost added the draft draft PR label Jul 21, 2022
Copy link
Contributor

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dreddy-work dreddy-work marked this pull request as ready for review August 10, 2022 21:23
@dreddy-work dreddy-work requested a review from a team as a code owner August 10, 2022 21:23
@dreddy-work dreddy-work added this to the 7.0 RC1 milestone Aug 10, 2022
@dreddy-work
Copy link
Member Author

dreddy-work commented Aug 11, 2022

Tests succeed locally. Seems thread awareness is not being set on lab machines. Looking on how to confirm this theory. Review can continue knowing test failed with lab specific issue.

Copy link
Contributor

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass over the docs only. Will continue to the code later.

@ghost ghost added the waiting-author-feedback The team requires more information from the author label Aug 11, 2022
Copy link
Contributor

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The animation is great, but we'll need to redo it. I understand that it's showing two desktops, but it's too wide (a lot of our users still use HD monitors), and it contains information completely unrelated (i.e., the email).
The app could be tweaked to appear significantly closer to the monitor boundary, so that we can clip the view and dragging will require less distance.
It could be also great to add some test to the animation to indicate each monitor's settings.

@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Aug 11, 2022
@dreddy-work dreddy-work requested a review from RussKie August 11, 2022 20:14
@dreddy-work
Copy link
Member Author

The animation is great, but we'll need to redo it. I understand that it's showing two desktops, but it's too wide (a lot of our users still use HD monitors), and it contains information completely unrelated (i.e., the email). The app could be tweaked to appear significantly closer to the monitor boundary, so that we can clip the view and dragging will require less distance. It could be also great to add some test to the animation to indicate each monitor's settings.

I tried but now screen separation isn't clear with latest one. I am sure people reading will understand and demo was just to show how it is picked up. Not planning on spending more time on this for now.

Copy link
Contributor

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed just the code-related changes, as this what we'll ship. We can iterate over the docs later.

LGTM with few minor changes.

@RussKie RussKie dismissed their stale review August 12, 2022 03:11

The code is looking good

@dreddy-work dreddy-work requested a review from RussKie August 12, 2022 04:36
Tanya-Solyanik
Tanya-Solyanik previously approved these changes Aug 12, 2022
Copy link
Contributor

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Copy link
Contributor

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some more nits

// Borrowed from https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/LocalAppContextSwitches.Common.cs
internal static partial class LocalAppContextSwitches
{
private const string ScaleTopLevelFormMinMaxSizeForDpiSwitchName = "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it internal for use in tests or access the private dynamically via the test helper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also going forward we might want to keep all these names in a special file, potentially in the common folder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on moving to a common file for these string const. Will make that change along with fixing skipped test. I enable auto-merge and it did merge when you approved.

/// </summary>
/// <param name="xScaleFactor">The scale factor to be applied on width of the property being scaled.</param>
/// <param name="yScaleFactor">The scale factor to be applied on height of the property being scaled.</param>
/// <param name="updateContainerSize"><see langword="true"/> to resize of the container control along with properties being scaled; otherwise, <see langword="false"/>.</param>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: break this line into multiple lines

@dreddy-work dreddy-work merged commit 01abac5 into main Aug 12, 2022
@dreddy-work dreddy-work deleted the dev/dreddy/fix7251 branch August 12, 2022 23:21
form.Show();

// Explicitly opt-in to resize min and max sizes with Dpi changed event.
const string runtimeSwitchName = "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the const from the source code here

Assert.NotEqual(form.MaximumSize, maxSize);

// Reset switch.
AppContext.SetSwitch(runtimeSwitchName, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If another tests that relies on this switch runs at the same time, you might have a problem. Perhaps these tests should be moved to the other test project, where they run sequentially.

@RussKie RussKie added the 📖 documentation: breaking please open a breaking change issue https://github.com/dotnet/docs/issues/new?assignees=gewarren label Sep 4, 2022
@RussKie
Copy link
Contributor

RussKie commented Sep 4, 2022

@dreddy-work a friendly reminder that this change must be documented, please raise a new "breaking change" issue at https://github.com/dotnet/docs.

@RussKie
Copy link
Contributor

RussKie commented Oct 18, 2022

@dreddy-work has a breaking doc issue been raised?

@dreddy-work
Copy link
Member Author

@dreddy-work has a breaking doc issue been raised?

Its linked above.

@RussKie
Copy link
Contributor

RussKie commented Oct 18, 2022

Ah, right, thanks!

The doc: dotnet/docs#31020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📖 documentation: breaking please open a breaking change issue https://github.com/dotnet/docs/issues/new?assignees=gewarren
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Runtime configuration support for Winforms in .NET Changing MinimumSize of Form activates the form
3 participants