Skip to content

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

Merged
dreddy-work merged 8 commits into
mainfrom
dev/dreddy/fix7251
Aug 12, 2022
Merged

Update Form's Minimum and Maximum sizes with DPI_CHANGED event#7467
dreddy-work merged 8 commits into
mainfrom
dev/dreddy/fix7251

Conversation

@dreddy-work

@dreddy-workdreddy-work commented Jul 20, 2022

Copy link
Copy Markdown
Member

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

@ghostghost added the draft draft PR label Jul 21, 2022

@RussKieRussKie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
@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 ownerAugust 10, 2022 21:23
@dreddy-workdreddy-work added this to the 7.0 RC1 milestone Aug 10, 2022
@dreddy-work

dreddy-work commented Aug 11, 2022

Copy link
Copy Markdown
MemberAuthor

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.

RussKie
RussKie previously requested changes Aug 11, 2022

@RussKieRussKie left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
@ghostghost added the waiting-author-feedback The team requires more information from the author label Aug 11, 2022

@RussKieRussKie left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
@ghostghost removed the waiting-author-feedback The team requires more information from the author label Aug 11, 2022
@dreddy-work

Copy link
Copy Markdown
MemberAuthor

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.

@RussKieRussKie left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
Comment threadsrc/System.Windows.Forms/src/System/Windows/Forms/Form.cs Outdated
@RussKie
RussKie dismissed their stale reviewAugust 12, 2022 03:11

The code is looking good

Tanya-Solyanik
Tanya-Solyanik previously approved these changes Aug 12, 2022

@Tanya-SolyanikTanya-Solyanik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.

Comment threaddocs/WinformsRuntimeConfiguration.md Outdated
Comment threaddocs/WinformsRuntimeConfiguration.md Outdated

@Tanya-SolyanikTanya-Solyanik left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
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 mainAug 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
Copy Markdown
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
Copy Markdown
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.

@RussKieRussKie 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
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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

@dreddy-work

Copy link
Copy Markdown
MemberAuthor

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

Its linked above.

@RussKie

Copy link
Copy Markdown
Contributor

Ah, right, thanks!

The doc: dotnet/docs#31020

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

📖 documentation: breakingplease 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

@dreddy-work@RussKie@Tanya-Solyanik