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

Fixing scaling issue with initializing Form on non-primary monitor with different DPI settings. #5557

Merged
merged 8 commits into from
Sep 7, 2021

Conversation

dreddy-work
Copy link
Member

@dreddy-work dreddy-work commented Aug 26, 2021

In this case, Form Handle is created according to the Secondary monitor DPI hence, doesn't receive DPI_CHANGED message.
Fix is making sure we scale the Form according to DPI when Handle is created.

Fixes #4854 and related issues.

Microsoft Reviewers: Open in CodeFlow

…th different DPI settings.

In this case, Form Handle is created according to the Secondary monitor DPI hence, doesn't receive `DPI_CHANGED` message.
Fix is making sure we scale the Form according to DPI when Handle is created.

Fixes #4854 and related issues.
@ghost ghost assigned dreddy-work Aug 26, 2021
@RussKie RussKie added the 📭 waiting-author-feedback The team requires more information from the author label Aug 27, 2021
@dreddy-work
Copy link
Member Author

@Balkoth , this change is helping scale the Form initialization on the secondary monitor. I see couple of issues in this regard raised by you. Will you be able to verify some of your scenarios with this branch? Note: This is handling only the Form and you might still have issues with child controls in it.

@ghost ghost removed the 📭 waiting-author-feedback The team requires more information from the author label Aug 30, 2021
@dreddy-work
Copy link
Member Author

@Balkoth , this change is helping scale the Form initialization on the secondary monitor. I see couple of issues in this regard raised by you. Will you be able to verify some of your scenarios /apps with this branch? Note: This is handling only the Form and you might still have issues with child controls in it.

@dreddy-work dreddy-work marked this pull request as ready for review August 30, 2021 20:58
@dreddy-work dreddy-work requested a review from a team as a code owner August 30, 2021 20:58
Tanya-Solyanik
Tanya-Solyanik previously approved these changes Aug 30, 2021
Copy link
Member

@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, why is it marked as "work in progress"?

RussKie
RussKie previously approved these changes Aug 31, 2021
Copy link
Member

@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.

👍 modulo the comments

@Tanya-Solyanik Tanya-Solyanik added the 📭 waiting-author-feedback The team requires more information from the author label Sep 1, 2021
@Balkoth
Copy link
Contributor

Balkoth commented Sep 1, 2021

@Balkoth , this change is helping scale the Form initialization on the secondary monitor. I see couple of issues in this regard raised by you. Will you be able to verify some of your scenarios /apps with this branch? Note: This is handling only the Form and you might still have issues with child controls in it.

I really would want to help, but once again i can not figure out how to build the project in Visual Studio 2019. I have tried with the virtual machine WinDev2106Eval patched to latest, installed everything mentioned in the Developer Guide and it still does not work. I start Visual Studio through an administrator developer prompt with the provided start-vs.cmd batch file.

I am really tired of messing around trying to build this. If you seriously want anyone outside of microsoft to contribute to this, please provide correct instructions or provide an actual uptodate developer vm where everything is setup to build bleeding edge version of winforms.

@RussKie
Copy link
Member

RussKie commented Sep 1, 2021

.NET 6.0 projects can only be built in VS 2022.

@Balkoth
Copy link
Contributor

Balkoth commented Sep 1, 2021

Sorry, but this is the wrong location to put such information. Put it in ADVANCE into the developer guide where everyone can see it.

@ghost ghost removed the 📭 waiting-author-feedback The team requires more information from the author label Sep 1, 2021
@dreddy-work
Copy link
Member Author

dreddy-work commented Sep 1, 2021

Sorry, but this is the wrong location to put such information. Put it in ADVANCE into the developer guide where everyone can see it.

@Balkoth, I agree that there is a need to update our documentation to current state. There are couple of other sections, that went out of date. We will be looking into it in the coming days. If you do not have VS 2022, building from command line should always work. Did you try that? Once you have updated binaries, rest of the process to test them should work as defined in the docs. Let me know how it goes.

@dreddy-work dreddy-work added the ready-to-merge PRs that are ready to merge but worth notifying the internal team. label Sep 2, 2021
@dreddy-work dreddy-work added 📬 waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) ready-to-merge PRs that are ready to merge but worth notifying the internal team. and removed ready-to-merge PRs that are ready to merge but worth notifying the internal team. labels Sep 2, 2021
@RussKie
Copy link
Member

RussKie commented Sep 7, 2021

Take it in RC2?

@dreddy-work
Copy link
Member Author

Take it in RC2?

Not for RC2. Change touches the flow of Handle creation that impact all modes.

@dreddy-work
Copy link
Member Author

@Balkoth , I am merging this but i would still love your validations here. Let me know how i can help on this. Command line build is expected to work but if you still have issues, let me know.

@dreddy-work dreddy-work merged commit 9b77d91 into main Sep 7, 2021
@dreddy-work dreddy-work deleted the dev/dreddy/SecondaryMonitorInitiation branch September 7, 2021 17:20
@ghost ghost added this to the 7.0 alpha1 milestone Sep 7, 2021
@Balkoth
Copy link
Contributor

Balkoth commented Sep 7, 2021

I will try my best to do a build tomorrow.

@Balkoth
Copy link
Contributor

Balkoth commented Sep 8, 2021

So i successfully can do a command line build with an VS2019 administrator developer shell using "build.cmd". Now how can i get an existing c# winforms project to run with the built binaries?

@RussKie
Copy link
Member

RussKie commented Sep 8, 2021

There are few ways

  1. In cli: prepend the .\winforms.dotnet to the %PATH% then run exe from the cli
  2. Copy the private binaries over to the global dotnet, e.g. https://github.com/dotnet/winforms/blob/main/docs/debugging.md#1-copy-your-changes-into-the-sdk

@dreddy-work
Copy link
Member Author

I normally use the second option. It is easier when running in debug or from VS.

@RussKie
Copy link
Member

RussKie commented Sep 9, 2021

I have a script that helps automating the 2nd step: https://gist.github.com/RussKie/bb11e213f04729603e533856865922c1

@Balkoth
Copy link
Contributor

Balkoth commented Sep 9, 2021

I did a pull on winforms/main and did a fresh build. An empty winforms app created from the default template crashes:
image

@RussKie
Copy link
Member

RussKie commented Sep 9, 2021

Looks like you're using Preview7 for your tests, but building Windows Forms from the main (which is .NET 7.0, but very close to .NET 6.0 RC2/GA). This won't work as there are several months worth of changes between Preview7 and the main.
You need to install the latest RC2 and drop the private binaries in it.

@Balkoth
Copy link
Contributor

Balkoth commented Sep 9, 2021

I installed what was recommend by the app launcher when i was directed to a microsoft site. Do you have a link as a quick google-search does not yield any results: https://www.google.com/search?q=.net+6+Release+Candidate+2

@RussKie
Copy link
Member

RussKie commented Sep 9, 2021

Apologies, I should've added the link. You can find nightlies at https://github.com/dotnet/installer, scroll down the page and you'll see a bunch of links.
I see we publish net7 already, so probably worth testing against it (it still uses net6.0 TFM).

@Balkoth
Copy link
Contributor

Balkoth commented Sep 9, 2021

Ok, i got it to run, but the fix does not work. The form is not centered on my secondary screen:
image

My sample for testing is avaialble here:
WinformsDpiTests.zip

@dreddy-work
Copy link
Member Author

dreddy-work commented Sep 9, 2021

Ok, i got it to run, but the fix does not work. The form is not centered on my secondary screen:

Thanks @Balkoth, I will take a look at the positioning of the form. Have you noticed any scaling issues with the form on secondary monitor? lets discuss this further on the issue #5729

filipnavara pushed a commit to emclient/winforms that referenced this pull request Nov 11, 2021
…th different DPI settings. (dotnet#5557)

* Fixing scaling issue with initializing Form on non-primary monitor with different DPI settings.

In this case, Form Handle is created according to the Secondary monitor DPI hence, doesn't receive `DPI_CHANGED` message.
Fix is making sure we scale the Form according to DPI when Handle is created.

Fixes dotnet#4854 and related issues.
filipnavara pushed a commit to emclient/winforms that referenced this pull request Dec 27, 2021
…th different DPI settings. (dotnet#5557)

* Fixing scaling issue with initializing Form on non-primary monitor with different DPI settings.

In this case, Form Handle is created according to the Secondary monitor DPI hence, doesn't receive `DPI_CHANGED` message.
Fix is making sure we scale the Form according to DPI when Handle is created.

Fixes dotnet#4854 and related issues.
@ghost ghost locked as resolved and limited conversation to collaborators Jan 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📬 waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) ready-to-merge PRs that are ready to merge but worth notifying the internal team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WinForms HighDPI PerMonitorV2 windows launched on secondary monitor is incorrectly scaled
4 participants