Windows Forms application on Windows 10 not scaling properly - winforms

When running one of our Windows forms applications on Windows 10, the GUI looks pretty bad since the scaling seems to be messed up.
Here are some 1920x1080 screenshots (note the different sizes of the second pair):
The scaling option in the Windows 10 Display settings is set to 100% (so no extra scaling should be applied).
Furthermore, the following code is executed at program start:
static void Main()
{
if (Environment.OSVersion.Version.Major >= 6) //Windows Vista and higher
SetProcessDPIAware(); //disable DPI scaling (or something like that) to avoid scaling problems on Windows 10
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(Hauptmenue.Instance);
}
This code block helps a little, since it looks a lot worse on Windows 10 without.
But this is not good enough...does anyone know how to "restore" the GUI to look exactly like on Windows 7 or 8?

Try to change settings on Windows 7 and Windows 8 to 100%. I don't think that it's a Windows 10 problem. Probably that's because default settings in Windows 10 are different.
You can try to "play" with AutoScaleMode Enumeration.
Try to set the mode for the form to None or to Dpi like described here:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
Also read the answer in this SO question about scaling in different controls.

I had a similar problem. Certain groupboxes were showing too wide on a Windows Forms application. It worked on a Windows 7 laptop, but not a Windows 10 one.
Setting the DPI scaling from 125% to 100% on Windows 10 worked for me. AutoSizeScaleMode was font.

Related

AutoScaleMode being ignored

I'm writing a WinForms C# application on a 4K laptop in Visual Studio Community 2017.
By default I have my Windows 10 Pro scaled to 150%. I have AutoScaleMode = none on every form and every user control.
I run my application and yet it still is scaled to 150%. I'm running VS as a DPI unaware process, and at design time my control are the right (small) size. I don't think it matters but I thought I'd mention it anyway.
Running Windows 10 Pro, fully updated.

WPF Formatting Issues for Fonts Between Windows 8 and Windows 7

I have written a basic WPF VB.net application, in Visual Studio 2012 in Windows 8.
The program basically takes over the full screen and displays text that is supplied from a XML it is meant to fill the screen based on the screen resolution and size.
The problem that I am having is to do with formatting. If I run the application up in Windows 8 the text will fill the screen correctly.
As soon as I run the application in Windows 7 on any PC it seems to change the spacing and end up leave space at the bottom of the screen.
I have checked the follow and not been able to find any reason for it:
1. Screen resolution (they are both running 1650 X 1080 at 96 dpi)
Copied the Fonts from the Windows 8 install ( no change)
Tried a different types (Tahoma, Segoe, Century Gothic) nothing changes .
Checked over all setting on Windows 7 (With or with out Aero theme, with or without Taskbar)
This is a similar issue to what I have
Differing char spacing in a WPF RichTextBox
But this still has not fixed my issue. ( http://msdn.microsoft.com/en-us/library/vstudio/system.windows.media.textformattingmode%28v=vs.100%29.aspx)
Any help on this would be great as I am really stumped to what the actual issues is and or could be.
here is some images of what the issues are
http://tmblr.co/Z3zZjsgWM-BG

Graphics.CopyFromScreen sometimes captures transparent window, sometimes not

I'm using System.Drawing.Graphics.CopyFromScreen to grab a partial screenshot of the desktop. I've noticed some curious behaviour. On some machines, when the application (WPF) window has AllowsTransparency="True", calling CopyFromScreen will capture whats 'under' the window. But on other machines, it captures the calling window too.
I've tried it on a number of machines, and operating systems, and haven't found a pattern. On XP and Windows 7 laptops it captures under the transparent window. On one windows 7 desktop we have, it captures the window itself. Aero, or other Windows 7 display features seem make no difference.
Could it be a graphics card issue? Is there any way to get consistent behaviour across all machines, or to predict or detect when this issue will occur?
EDIT Thanks to the link provided by Hans Passant below, and some further testing, I now understand that this issue connected to window transparency only. On some machines, CopyFromScreen captures all windows, on other machines it only captures non-transparent windows.
Not so sure about the sometimes-not behavior. Layered windows have been behaving oddish since Aero. What is definite is that Graphics.CopyFromScreen() will not capture layered windows by default unless you use the overload that specifies the CopyPixelOperation. The required option is CaptureBlt, described as:
Windows that are layered on top of your window are included in the resulting image. By default, the image contains only your window.
Which is not accurate, "your window" won't be captured if it is a layered window. What's worse is that the method has a bug. You don't only need CaptureBlt, you also need SourceCopy. And the argument validation code doesn't permit that combination, you'll get an InvalidEnumArgumentException when you try to use it.
Well, GDI+ is a bag 'o bugs. You'll find the ugly pinvoke code you'll need to work around this in this answer.

Visual Studio and DPI issue

I am developing a Windows Forms application using VS2008 on Windows Vista. I tried to run my application on Windows XP the other day, and everything on GUI was messed up. I realized that I developed the application using 120 Dpi setting on Windows Vista and my XP was set to 96 dpi.
My application has several UserControls and all of them shrinks even in the Visual Studio itself if I change my DPI to 96. I am sure a lot of people are using Visual Studio in high DPIs these days. So how can make sure that my GUI does not get messed up both in Visual Studio and runtime?
EDIT: I have read couple articles on this issue and I learned that I should be setting AutoScaleMode to None. However, this still does not prevent my labels to adapt new DPI settings enforced by the operating system. I need a way to prevent my labels to grow/shrink because other GUI elements have fix sizes.
It has been a while since I worked on this issue, but try setting AutoSize = False. In addition, UseCompatibleTextRendering = True might help.
This is a rather old question, but I want to share my solution/opinion. I ran into a similar problem recently. Actually, I want Visual Studio to keep my WinForms as they are, but them to scale at runtime. I found no consistent summary on how to correctly do that. After some reading and experimenting I came to this solution:
Keep the Form’s AutoScaleMode = Font.
Set in your Forms Designer: Font = MS Sans; 11px
In the Forms Ctor, after InitializeComponent, set: Font = SystemFonts.DefaultFont
Enable DPI-Awareness, either through a manifest or by API function SetProcessDPIAwareness
Since AutoScaleMode remains active, all DPI-changing magic works, even per-monitor DPI awareness. What remains, is designing Forms in a way scaling works nicely.
I wrote the details on my Blog: http://www.sgrottel.de/?p=1581&lang=en

Why is UseCompatibleTextRendering needed here?

I think I'm missing something fundamental. Please tell me what it is, if you can.
I have developed a little C++ WinForms app using VS2008. So it is built using .NET 3.5 SP1.
My development box is Win7, if that matters.
The default value of UseCompatibleTextRendering property in WinForms controls is false in this version of VStudio. And this should not matter to me, I don't think. I don't have any custom-drawn
text or controls.
The app looks good running on my Win7 box.
If I package it up (dragging along .NET 3.5) and install it on one of our WinXP desktops, the buttons and labels don't look good; the text is chopped off in them.
If I set UseCompatibleTextRendering to true and then run it on the XP boxes, the text fits into the
buttons and labels.
My question is: Why? The installation puts .Net 3.5 on the XP boxes, so the app should be able to find and use the right version of WinForms, right?
I should note that before I put my app + .NET 3.5 on these boxes, they have no .NET at all. They do not get automatic Microsoft updates; our IT guy gates the patches and upgrades.
[ This sort of thing has happened before with apps I create.. they look/work great on the Engineering machines, because we maintain those and they mostly have up-to-date stuff. When they are run on the corporate boxes, they usually don't run and need the VCredist installed. ]
Back to the question at hand: The text looks better with the UseCompatibleTextRendering set to false, so I'd rather keep it that way, if I can. I'd like to understand what might be missing on those XP boxes that is making the text not fit.
Thanks
S
It is probably a scaling problem, the XP machine may have a different video adapter DPI setting or a different system font size. Scaling is affected by the form's AutoScaleMode and whether or not they "inherit" the container control's Font property. Which it does if the Font property isn't bold in the Properties window.
One quick way to check if scaling works property in your Form:
protected:
virtual void OnLoad(EventArgs^ e) override {
this->Font = gcnew System::Drawing::Font(this->Font->FontFamily,
this->Font->SizeInPoints * 125 / 96);
}
That scales it up. It probably gets scaled down on the XP machine, use 96/125.

Resources