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

Location 0, 0 not working on windows 10 #4776

Closed
thanhhn253 opened this issue Apr 12, 2021 · 19 comments
Closed

Location 0, 0 not working on windows 10 #4776

thanhhn253 opened this issue Apr 12, 2021 · 19 comments
Assignees
Labels
area-HDPI-SA Issues related to high DPI SystemAware mode tracking-external-issue An issue is caused by an external system and won't be fixed in this repo won't fix-by design Behaviour is by design

Comments

@thanhhn253
Copy link

Steps:

  • Create new windows form app
  • Set StartPosition = Manual
  • Set Location = 0, 0
  • Run the app
  • The app does not display at 0, 0

Please fix!

@thanhhn253
Copy link
Author

thanhhn253 commented Apr 12, 2021

And if you set Height = Screen.FromHandle(Handle).WorkingArea.Height; it will leave some space at the bottom

@RussKie
Copy link
Member

RussKie commented Apr 12, 2021

Please provide a sample app and screenshots.

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Apr 12, 2021
@thanhhn253
Copy link
Author

thanhhn253 commented Apr 12, 2021

@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Apr 12, 2021
@RussKie RussKie added 🪲 bug Product bug (most likely) area-HDPI-SA Issues related to high DPI SystemAware mode labels Apr 14, 2021
@RussKie RussKie added this to the 6.0 milestone Apr 14, 2021
@dreddy-work dreddy-work modified the milestones: 6.0, 7.0 alpha1 Aug 27, 2021
@RussKie RussKie modified the milestones: 7.0 Preview1, 7.0 Preview2 Jan 24, 2022
@dreddy-work dreddy-work modified the milestones: 7.0 Preview3, .NET 7.0 Mar 22, 2022
@dreddy-work dreddy-work modified the milestones: .NET 7.0, .NET 8.0 Aug 15, 2022
@mcsilver
Copy link

Hi, what's the status of this one for WinForms and .NET Framework 4.7.2, please? I'm noticing the same thing.

@dreddy-work
Copy link
Member

dreddy-work commented Aug 19, 2022

This is something that may need to address with Operating System. Other native tools show this window is actually located at 0,0 and that make me think drawing of the window is off here. @mcsilver , did you try with a native (MFC) application?

image

@Olina-Zhang can you check this with native app?

@mcsilver
Copy link

mcsilver commented Aug 19, 2022

Hi @dreddy-work, this may be a problem of understanding more than a problem with the software. In your screenshot, I see that the window's position shows in WinSpy++ as (0,0) but its location on the screen does not appear to be against the left edge of the screen, in my opinion, whereas its top is. Why would its left edge not be touching the edge of the screen when its location is (0,0) whereas its top edge is?

@Olina-Zhang
Copy link
Member

@Olina-Zhang can you check this with native app?

@dreddy-work MFC native dialog- application has the same testing result:
image

@RussKie
Copy link
Member

RussKie commented Aug 22, 2022

If an MFC app is exhibiting this behaviour, then this is likely a Windows level bug.

@mcsilver
Copy link

Crazy! Okay, thanks.

@dreddy-work
Copy link
Member

Opened an internal bug in Windows repo and will be tracking the issue there. @mcsilver , to track the progress publicly, you may want to open a feedback ticket for Windows operating system via one of the channels defined here

@ghost ghost removed this from the .NET 8.0 milestone Aug 22, 2022
@mcsilver
Copy link

That's great, @dreddy-work. I took your suggestion.

@RussKie
Copy link
Member

RussKie commented Aug 23, 2022

Out of curiosity, does a WPF app exhibit the same?

@Olina-Zhang
Copy link
Member

Out of curiosity, does a WPF app exhibit the same?

Yes, it is same.
image

@dreddy-work
Copy link
Member

dreddy-work commented Aug 25, 2022

Response from OS team for reference:

This behavior is by design (oddly enough). In Windows 10 the design was changed so that window borders would have thin (1px at 96 DPI) borders.

Literally switching to 1px of non-client area on the edges wouldn't work out because grabbing the edges with the mouse would be too hard. So, the amount of non-client space on the edges was left as 8px wide, but 7px of that space is now transparent. The programmatic edge of the window is now in a different position than the visible edge of the window.

That is case on the sides and bottom of the window, but wasn't necessary on the top edge.

Apps can query the amount of this transparent space with DwmGetWindowAttribute + DWMWA_EXTENDED_FRAME_BOUNDS. But note that that API is NOT DPI virtualized, and will return raw physical pixels regardless of the DPI awareness mode of the caller. That means that it will work fine for per-monitor-aware apps, but will return confusing answers to unaware or system-aware apps.

You can indirectly see this behavior with winspy. The red selection overlay thing is the positioned around the true window bounds (aka GetWindowRect), but you can see on the sides and bottom that the visible border is inset quite a bit from that.

You will also notice that the mouse cursor changes to the resize cursor outside the windows border.

Image
image

Image
image

@mcsilver and @thanhhn253 as FYI.

@mcsilver
Copy link

mcsilver commented Aug 25, 2022 via email

@RussKie RussKie added won't fix-by design Behaviour is by design tracking-external-issue An issue is caused by an external system and won't be fixed in this repo and removed 🪲 bug Product bug (most likely) labels Aug 25, 2022
@dreddy-work
Copy link
Member

Am I missing something, or could these changes be implemented without ill effect?

This is the windows decision based on feedback they received. Windows team/feedback channel might be the best place to chat further on this.

@thanhhn253
Copy link
Author

So now we need to set Location: (-7, 0) right?
Is it always 7px or it depend on the monitor resolution?
Can you provide C# code to get the transparent space width?

Sorry for the late response!

@RussKie
Copy link
Member

RussKie commented Sep 14, 2022

As per the Windows team response posted above:

Apps can query the amount of this transparent space with DwmGetWindowAttribute + DWMWA_EXTENDED_FRAME_BOUNDS. But note that that API is NOT DPI virtualized, and will return raw physical pixels regardless of the DPI awareness mode of the caller. That means that it will work fine for per-monitor-aware apps, but will return confusing answers to unaware or system-aware apps.

Windows Forms SDK will not be providing API for this.

@mcsilver
Copy link

mcsilver commented Oct 11, 2022 via email

@ghost ghost locked as resolved and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-HDPI-SA Issues related to high DPI SystemAware mode tracking-external-issue An issue is caused by an external system and won't be fixed in this repo won't fix-by design Behaviour is by design
Projects
None yet
Development

No branches or pull requests

5 participants