The Windows Forms code generated by Visual Studio when modified by the designer is not the same if I develop of Windows 8.1 than if I develop in Windows 10. This will result in all my sizes to be increased by a factor close to 1.5 (from Windows 8 to Windows 10).
This might look like an autoscale in order to fit the screen resolution. The problem is that a lot of my code depends heavily on the size and thus the impact is way more than just a "resize" of my whole screen. The generated code also add some margin and padding.
Is there a way to disable all these OS related changes when I modify the code?
Related
I'm using Visual Studio 2013/2015 and my operating system is Windows 10. I would like to know why my WinForms controls look so flat. I have both enabled and disabled EnableVisualStyles. Perhaps this is a Windows 10 issue? Why would these controls be lacking a 3D look and feel?
Thanks much,
The windows 10 theme itself is very flat, and winforms adopts the visual style of whatever version of windows you are running.
So you aren't doing anything wrong, that is just how windows 10 UI elements look.
If you were to run your application on windows 7, it would look more 3D.
I had been developing WinForm apps in a long time. I just recently bought a Surface Pro 3 to serve as my new development PC. Unfortunately I noticed an issue with the GUI editor. The some of the sizes of the controls don't match with what appears in the GUI editor and with what appears in the actual running application. For example, the sizes of my panels don't follow what it looks like in the GUI editor when I run the app. They usually increase in dimension. I am not really sure if it is a VS issue or maybe it has something to do specifically with using Surface Pro 3?
To demonstrate what I mean consider the following screenshots. Notice the difference in the size of the Menu Bar in the GUI Editor and in the actual application.
If you want to prevent your app from changing size, you can make it independent of DPI settings. Your app will be pixel perfect but on high resolution screens may be too small.
All you have to do is to change AutoScaleMode property of the main form and set it as None.
I know this is an old thread but I was experiencing the same issue... I found a workaround which you may find useful...
After trying a few things it became obvious to me that windows 10 was attempting some "intelligent" resizing of forms under Windows 10 on the surface pro (I am using a surface pro 4)... I am not sure if it is a win10, high-res or surface pro issue.... whatever it is it was messing up my control sizing, placement, anchors and resolution.
I found that if I made a note of the intended size of my form in the designer and then manually set this in code at the end of my Form_Load event, it would override this unintended behaviour and I ended up with my originally intended form size and control placement, I also needed to re-center the form in the parent/screen to get the desired result (of course only if that is the intended start-up position for your form)
The code that worked for me (at the end of the Form_Load event) is...
this.height = 800;
this.width = 600;
this.CenterToScreen();
I hope this helps somebody, I was pulling my hair out for a while!
It has been a while since I posted this question and I kinda forgot about it. I thought I should share my recent findings for those who will find themselves in this same predicament.
I learned that the discrepancy between the GUI editor and the actual running app was because of the super high DPI scaling of my Surface Pro 3. Visual Studio was automatically running at 216 DPI (225% display scaling) compared to the usual 96 DPI (100% display scaling) of common computers. My workaround back then was to simply adjust my controls accordingly thru trial and error and to anchor most of them between the GUI editor and the running app. Eventually, it became less of an issue since I moved on to a normal desktop with a normal screen for my regular software development. Moving forward, I recently stumbled upon a Microsoft documentation regarding Automatic Scaling in Windows Forms. It explains the issues with multiple DPI scaling for Windows Forms. It also includes this bit about the DPI scaling issue of Visual Studio:
With the extreme differences in display DPIs, especially in modern 2-in-1 devices, this can still happen with the most current versions of the .NET Framework and Visual Studio. To address this in a team using different DPI displays, make sure Visual Studio always starts in a non-DPI-aware mode, so the Windows Forms designer always bases the layout calculation on 96 DPI.
The solution they suggested is to add or import a registry value that disables Visual Studio's High DPI awareness:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\devenv.exe]
"dpiAwareness"=dword:00000000
I tried it and it definitely works. I hope it helps you too. :)
I have created a wallpaper changing program in C# using Visual Studio and I have had a couple reports in this last few months of part of the program not displaying right. I have no clue what is causing it. Any help?
This is what it looks like on my computer, Windows 7
This is what it looks like on the victims computer, Windows 8
If this is a windows Forms application, it could have something to do with DPI/resolution scaling. This isn't unique to Windows 8.
Check the Display sizing options match on both displays (or simply change on your Windows 7 Machine) in Control Panel.
Control Panel\Appearance and Personalization\Display for Windows 8. (I think it is the same for Windows 7).
See C# WinForms disable DPI scaling
or
How to write WinForms code that auto-scales to system font and dpi settings?
Ok, I am aware of developing high dpi applications in WinForms and WPF, but while testing some features in Windows8, I stumbled upon something weird.
I have a WinForms application with AutoScalingMode set to DPI. The form has a bunch of labels. All the labels' font units are measured in points but one (the red label which reads "This text block is special. Its size is 18px"), as its size is set to 18px and not pt.
I ran the application in Windows 7 as well as Windows 8.
Windows 7 does not auto scale this (the red one) label as expected but Windows 8 auto scales the same label!
What could be the issues? Is there a documented statement from Microsoft stating that Auto Scaling set to None won't work in Windows 8?
Okay, I guess I found the reason. I will have to disable the DWM settings to "Disable display scaling on high DPi settings". If I do so, then it is not scaling the text in Windows 8.
But I did not have to do this in Windows 7 and still it works fine! Wondering why..!
I am developing a C# application with .NET Framework 2.0.
The problem is, that on my client's PC, the controls get expanded, layout changes (positions of the controls gets changed), sometimes buttons get missed entirely. It happens even on Forms with 2-3 TextBoxes, 2-3 Buttons and some Labels. I tried a lot of investigations. I tried to show a message in the form's resize event. But it doesn't get called. After digging a bit more, it seemed that in Designer.cs file even though ResumeLayout (false) is being called for the form, but this causes the the expansion/disposition of the controls.
My Client is using Windows XP professional on his Dell laptop. He is able to reproduce the issue on other laptops with Windows XP professional. But not in other OSes (like Windows XP Home or Windows Vista). In my desktop with Windows XP professional, it is not reproducible.
How can this issue be resolved?
Are you sure it has anything to do with the OS? It sounds more like a dpi issue. 'Normal' is 96 dpi. If the form was designed at 96 dpi, it would probably look different at a different setting.
See this article for how to check/change the dpi settings in XP.
Edit: I forgot to mention that you can use the TableLayoutPanel Control to layout your form. Using the auto-sizing capabilities will help keep things looking 'normal' at any dpi setting.
It's probably due to the DPI setting in Windows XP.
If you're using the standard (96) DPI setting, but they're setup using a alternative one (ie: 120), it often will mess up layouts of controls.
The "right" way to handle this is to try to automatically build your layouts using layout elements that can resize as needed. This is difficult in Windows Forms (and one of the things WPF fixes).