Disabling windows 10 scaling for specific application - c#

I am having issues with some applications (mainly dashboard) that some user uses windows display scaling to make their icons bigger but this cause huge problems in my software. I am looking for a way to disable completely the scaling on my application and leave the application scaled to the pixels of the display resolution instead.
I have found this thread but it is 8 years old and windows 10 didn't exist at the time and another user gave an answer but it doesn't work either.
A simple example of the behavior happen mostly on dashboards as there is a lot of controls and widget on these kind of screens and they are critical for thing like robot machinery controller.
One example dashboard window is in it's minimum possible size 1900 x 980 (could be 4-5 pixel smaller in both direction but we rounded up to get rounded positions XY values). This resolution is just shy of 1920 x 1080. It Cannot be smaller but you can make it larger if you have a bigger screen like 4K and all you gain is more date in treeviews, better display in the 3d Engine renderer etc.
So some users have small laptop screen such as 15 inches that have a maximum resolution of 1920 x 1080 resolution but they use 150% scaling so my screen minimum size become 2850 x 1470 in their screen which make the application bigger than the screen and goes outside the screen.
An another example if i use a Windows Surface Pro which have a 2736 x 1824 resolution which is about 80% bigger than 1920 x 1080 the window does indeed still take the original 1900 x 980 pixels on the screen which make it look quite small so if you full screen it you see much more information in all controls. But then if you change scaling to 150% the screen now take again 2850 x 1470 pixels on the screen which is fitting perfectly on the height but on the width i am short by 100 pixels, and 100 pixels that's enough to loose the right part of my screen and you either cannot see the left most part or the right most part of the screen.
I tried the 3 auto scaling mode : DPI, Font and None and it doesn't work at all. It still stretch the screen no matter what. Changing the font of the forms doesn't help either, i manage to make it once work for few labels directly in the form but anything inside group box fail to change or grow twice in size compare to the rest.
Important points :
Project are .net 4.5 and 4.6 but there is no problem compiling them in 4.7if i need to for specific features.
WPF is out of the question. We took 3 years to implement it and ended up quickly with very bad performance with third party DLL and 3D Cad performance were simply abysmal.
Screens are already optimized with the least amount of controls possible. out of the couple hundreds of screen and thousands of user controls about half of them are very close to the limit of 1920 x 1080 which is around 90% of our clients
I have received a suggestion of running a Virtual Machine on the client computer with 100% scaling which is not affected by the host computer. It is probably my last resort as it's very difficult to handle dedicated video card through VM especially CAD card such as Quadro and FireGL.
Half the users use touch screen and we tried putting everything in a panel with 2 scrollbar and god it's awful and works once in a blue moon. So it's only good for mouse users and these users all have desktop AFAIK so 99% of them doesn't use scaling so they don't have the issue.
So is there anything nowadays that can fix or work around this issue ?

Did you try making your Process DPI aware?
You can either do it through a pinvoke:
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
and call
SetProcessDPIAware();
in your Main or create a Manifest and add
<dpiAware>true</dpiAware>
There is a tutorial here.
Declearing it DPIAware should stop windows from scaling by its own.

Related

How to scale window according to screen resolution in UWP?

I am new to Stackoverflow as well as UWP (My English is regular too). I apologize in advance for my bad writing.
I am developing a windows application in UWP/C#. My monitor size is 23' and it is set to 1920x1080 (100%) resolution.
As seen in image 1, I have configured the application in such a way that the size of the main frame is 1920x1080, therefore, when I run the application on my computer it looks perfectly (see image 2).
However, when I run the application on another computer with a smaller screen size (17 "), it looks like in image 3, where it can be seen that the application does not fit this size. It seems to keep the original size and mi application "does not fit on the screen".
My question is: how do I program the application so that it does not lose its shape, distribution, aspect ratio, or proportion when it is run on screens that are different in size from the computer on which it was programmed? In this way, it automatically adjusts to the resolution and scale of the screen, without losing the original proportion and distribution with which it was programmed and designed.
Thank you very much for your help and understanding.
EDIT 1: I am not looking for the content of the application to fit a change of the window, but rather to fit screens of different sizes. That is, the same content, distribution and proportion are scaled to fit on any screen size, as evidenced in image 3 that does not happen. (see Image 4)
I don't want the image 3 to happen.
The control doing exactly what you want is called ViewBox, but as people already suggested above, it would be better to design adaptive UI using triggers or at least grids.

UWP is not showing correct scale and resolution when run on local machine

I have build a UWP project in 12" tablet size (which I chose from options provided when I design the UI in designer)
However when I run the application, it is shown too big on my screen, my design could not shown completely on the screen.
For example, I have 2 buttons in my design form top to down, only the top one is shown but the below one is missing due to my screen is not big enough to show them. But my laptop screen is 15.6", and previously the program was run in another desktop with a 24" monitor and it shows correctly.
Is there anything I can do to change the resolution/scale of my application on the laptop screen? My laptop resolution is 1920x1080.
Thank you.
I think the resolution is 2160*1440 for 12" 150% scale, my laptop resolution is only 1920*1080, how do I change the resolution?
Windows automatically selects a scale factor for each display based on its DPI (dots-per-inch) and the viewing distance of the device. So that the scale factor is defined by the windows. Details please reference Effective pixels and scale factor.
Users can override the default value and by going to Settings >System> Display > Scale and layout settings page. You could change the scale to 100% for your laptop.

Do larger monitors slow down winforms applications?

Will WinForms apps run slower on larger monitors(i.e. larger resolution) as opposed to smaller all else being equal? My gut says yes, as there's more real estate to paint, but I cannot find any information anywhere regarding the effects.
I ask because we have a WinForms application that generally runs on two 22 inch monitors, but we have a couple users who run it on two 30 inch monitors, and they always seem to have more lag in their GUI than anyone using the 22 inch monitors.
The issue isn't really the number of inches, its the number of pixels.
Drawing to a 800x600 screen is less work than drawing to a 1920x1080 screen (roughly 4x less work).
Still, most of that work is likely done by a graphics card, and won't affect CPU load all that much.
Having graphics cards from competing chip makers (one nVidia and one ATI) may cause slow downs.
The application in question might also be poorly painting and it's not as obvious when the window is smaller but when it's bigger on the bigger displays the poor painting code is a bigger hotspot. You could try using a profiler to see what's going on. Visual Studio has one built in now, or you could try DotTrace http://www.jetbrains.com/profiler/
For the build-in winform controls, the difference won't be that much. In general, the rendering of these controls is pretty fast on any resolution.
Check if you are using custom painted controls. In many cases the performance is poor if the paint method is not implemented well. For example if you draw pixels (nested loops for width and height) the performance will slow down dramatically with increasing resolutions.
Another trick for custom controls is to enable double buffering, it can speed up things a lot for heavy paint routines:
public partial class YourControl : Control
{
public YourControl()
{
InitializeComponent();
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);
}

XNA Window Scaling Performance

In my XNA game, I program and design the entire thing for 1920x1080 resolution and then scale scale and letterbox to fit the running system (XBox or PC).
This has been a great solution as it allows me to only ever worry about one resolution.
However, I'm now wondering if this will come back to bite me in the future as the game becomes more complex.
Since I'm having to scale everything with every draw (I scale SpriteBatch.Begin() with the scale factor only once, do all drawing, then call End()), is this going to have any detrimental effect on performance? I know the XBox already does this for XNA games for you when set to 720p natively (which, I actually am when running on XBox, it just gets the appropriate scaling factor).... so I can't imagine it's too bad, even for the PC.
The xbox does its scale in a specialized scaler in the video output - there is zero performance hit to your app.
The scale factor you pass in to SpriteBatch just translates the vertices of your sprite. Its done with a factor of 1 even if you don't pass in a scale so there is no extra load there.
With different screen sizes there will be different fill rates (more or less pixels) and texture lookups will be different too so that will show some variances.
Just using a 1028x720 backbuffer is the safest to do. The xbox can hardware scale that into ANY resolution or ratio without a single line of code or any perf issues. It will letter box properly and the hardware scaler is very good quality. You cannot claim 1080p support is really the only downside.
If you chose 1020x1080 as your back buffer note that the hardware scaler cannot scale that down to 480i and WILL fail in peer review (well it should if anyone notices)
On WIndows the easiest thing is probably to draw everything to a RenderTarget and then just scale the whole darn thing on one go at the end. See the SpaceWar starterkit for the few lines of code it takes to do that. (All inside #if !XBOX so you dont waste cycles doing it on the 360)
This shouldn't cost you. The scaling is done by he video card.
However, if this does worry you, another option to handle different resolutions is to change the render target to an off screen buffer, render to that, and then draw a square on the screen with the buffer as the texture. More pixels are rendered, but you don't need to do a transform on each vertex.

Mimic/emulate a specific screen resolution for sizing WinForms?

I am currently developing a Winforms Application that will run on a very specific tablet PC.
My development environment uses dual-17" monitors which are far bigger than the tablet screen size of 10.4" (1024x768).
Due to the purchasing department at my company the delivery of the tablet will not be until well into the design cycle.
Is it possible to mimic the tablet size so that I can adjust my forms to match?
You have couple of options:
set one of your screens to the tablet resolution. You might need to move your taskbar to that screen to get the proper-sized workspace.
install Virtual PC and create a VM with the tablet resolution.
set your main form size explicitly to the tablet PC resolution. For best results size it to the proper workspace size, not the desktop size.
Note that your form will have to still be relatively flexible, since users might configure their taskbar to be at a different position, or different size, thus affecting the available workspace for your app.
The fact that you have 1024x768 on 10.4" means the pixels are denser than your typical PC monitor. That means that text 10 pixels high on your monitor might look fine, but 10 pixels high on the tablet PC may be tiny and almost unreadable (even without loss of resolution).
Unless you can find a monitor with similar pixel density, I don't think you can properly mimic it. Even if you can shrink the application to a 10.4" section of the monitor, now you're probably dealing with sub-pixel shading which will look blurrier than on the tablet PC.
The best you can probably do is setting one of your monitors to 1024x768 (without stretching to fill the screen!), or just set your app to that size and eyeball it to take into account that it will actually be smaller.
You could try hosting your main form inside a user control or another form limited to the relevant size. However, the form is then not a "top level" form, but fairly closely looks and behaves like one.
You can perform normal form actions (minimise / maximise / move / resize / etc) so you can get a feel for what it is like and a certain size.
However in this instance, its best to always design the UI for the minimum resolution you have to target, and have it scale upwards on larger monitors.
very easy - if you're concerned about size, or users have to use the touch screen, start your form out with 10pt+ font
very cool - design the form size as, oh, 950x650. Experiment with the anchor property of each control. Allows you to make basically totally resizable controls (if you get creative with the anchor on groupboxes/panels and the controls inside them).
then set your form to maximize itself on the tablet PC (or e.g., if screen size is <= 1280x1024 - the Anchor property has its limitations as to what size increase looks reasonable).

Categories

Resources