This question already has an answer here:
How to get DPI scale for all screens?
(1 answer)
Closed 4 years ago.
In a multi monitor enviroment, how can I find all screens and their DPI (which might not be the same)?
My users logs on from home via Remote Desktop and many of them have Surface Book which has high DPI and then a second screen with default DPI (96).
I know of the "PresentationSource.FromVisual", but that does not work for getting DPI for all screens.
Pretty simple actually.
a calculation using these values
screen.Bounds.Width;
screen.Bounds.Height;
screen.Bounds.Size;
combined with getting screens using Screen.AllScreens (System.Windows.Forms assembly)
and you're done.
Related
I am having an issue with auto scaling while trying to create a Windows forms app. I'm currently running on a Dell laptop with a 3840 x 2160 display (4K). I'm trying to add an image to a picture box, and if I leave the picture at its native size (which is quite small on my display) it appears at a correct autosized scale when I go to run the app. The issue with this is at the native picture's size it is very difficult to lay out all the other items I want to add to the app. If I increase the size of the picture to something that is usable it increase the size of the image to something large enough it doesn't fit on my screen. I know this is likely due to the auto scaling Windows 10 does, but I wanted to see if anyone else might have a work around for this? I've tried to see if there is a way to zoom in the display in the designer window, but I haven't found anything. I have also noticed the size of the windows forms app itself changes depending on where I have items placed on it.
I don't know that I completely understand what you're asking, but I would assume it could have something to do with the pixel units of your elements. Here's an excellent explanation of point-based vs pixel-based sizing
This question already has answers here:
Is the size of a Form in Visual Studio designer limited to screen resolution?
(8 answers)
Closed 8 years ago.
I am working on Windows form application. After deploying the application I am getting screens with different sizes in laptop and desktop. This makes some of my menus to disappear and reports to be not shown properly. Do we have a solution for this?
While changing the resolution of my system my form size also getting changing. I want to prevent this.
Make your app with lowest possible resolution (Like: 800x600) and then
Use Panels and when you add your tools into those panels dock them, that might be helpfull, that's what I am using in all my applications and it is going with screen resolution all the time.
I put this section of code in my Load event method:
this.MaximumSize = this.MinimumSize = this.Size;
When a user attempts to double click on the top of the form to maximise it, it stays in the same size. Therefore, maximising the form in this case is disabled.
Make it small enough to fit in the screen having the smallest resolution. And make your forms WindowState as normal. Then you'll see that it fits all the screens. But if you want Maximized state on all screens then you should first apply my first sentence, with #Nidzaaaa's answer.
This question already has answers here:
How to see/test responsive design on multiple devices simultaneously?
(2 answers)
Closed 9 years ago.
I have created a responsive webpage, now i need to check the pages on 3 breakpoints desktop, tablet and android.
Can anyone help for the tools to test the page on different widths
I usually use browser add-on, firesizer for firefox, and window resizer for Chrome.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C# WPF resolution independancy?
What is the difference between resolution of monitor and System DPI with relation to WPF resolution independence.
Changing what between the two keeps the size of window same in WPF which was earlier not possible in User32?
EDIT:
The book I am reading "Pro WPF in C Sharp" says that if we create a 1 inch button in 96 DPI and then later change the DPI to 120, due to more pixel density, the button would become small (in winforms).But I tried that and I can see that in both the two cases the button size remains the same !
Why is it so ?
Actually, the so-called resolution independence of WPF doesn't enable you to do anything you couldn't do before in Win32. It's just that it was a lot more work before. So the only real change here is one of develop effort - there's no change in the fundamental capabilities. (And that's true of everything in WPF actually. If you have several years of development time to spare, you can do everything WPF does by programming directly against DirectX APIs...)
WPF automatically takes into account the nominal DPI configuration. In Win32, if you want your application to be sensitive to the nominal DPI, you have to write additional code to make that happen, and you have to deal with various horrible layout issues if you want to avoid problems like text getting cropped with some DPIs. (Although now that we have GDI32-style text rendering in .NET 4, you can opt back into all those problems in WPF apps...)
So the answer to your question is essentially: no difference. WPF makes it much easier to take the DPI into account, but it doesn't enable any new behaviour here.
Fundamentally, WPF runs into exactly the same problems as classic Win32 apps for the simple reason that it has access to exactly the same information as classic Win32 apps. As the pages linked to in other answers here discuss, Windows usually has no idea what the DPI really is. Most of the time it'll tell you that the monitor is 96dpi. Well I've got 3 screens attached to my computer, and Windows is reporting 96dpi for all of them, even though none of them is really 96dpi, and they're not even all the same dpi in reality.
The bottom line is: Windows doesn't usually have any idea what the real DPI of your screen is. There's nothing WPF can do to overcome that. If there were a way for WPF to discover the real DPI, Win32 apps would be able to discover it too.
I'm trying to create a WPF window that will encompass the entire Desktop working area. In WinForms I'd do this by getting the Union of all the bounds in System.Windows.Forms.Screen.AllScreens.
Is there an equivalent type or other mechanism to get the bounds of the entire desktop in WPF or do I need to use the WinForms type?
Try SystemParameters.VirtualScreen* (Top, Left, Height, and Width) properties. http://msdn.microsoft.com/en-us/library/system.windows.systemparameters.virtualscreenheight(v=VS.100).aspx
Don't use winforms api because it doesn't take into account the fact that WPF's measurement units are not pixels. I came across this issue just recently because I'm losing my vision and have my monitor set to a higher dpi. The codebase I was working on used the Winforms Settings and the UI was larger than my screen.
If you're going to use the winforms api. Look at this blog post on calculating the DPI factor.
I have successfully used WpfScreenHelper 0.3.0.0, currently on Github or Nuget,
https://github.com/micdenny/WpfScreenHelper
It does what the .NET framework should have done so many years ago.
I needed to check if some coordinates exist on any screen in WPF, as in these:
Very germane: Determine if an open WPF window is visible on any monitor
Forms-only and inadequate WPF suggestions: Determining if a form is completely off screen
Just use WinForms. I do not think there is a direct WPF equivalent.
You could try SystemParameters.VirtualScreenWidth and associated parameters. That might not provide as good as a result as continuing with the WinForms API.
The only downside I can see with the WinForms type is an extra dependency and the larger working set related to that.