WPF Windows program displays in large fonts but only on one PC - c#

I have a WPF application rendering fonts to a larger size than I expect.
The catch is that only WPF applications I write seem to have this effect, and the problem happens only on one computer. The effect also happens with all WPF programs I write (not just one), and all windows exhit the effect.
I am using Visual Studio 2008 with .NET 3.5 SP1; all programs written in WPF.
The operating system is Windows XP with the latest service packs.
The screen resolution is 1680x1050.
Windows and buttons using Windows XP style.
Font size is Normal.
DPI setting is normal size (96 dpi).
I tested my applications on a two other computers with same OS and settings and it looks fine. My programs run on dozens of other computers and I do not see this problem.
Here is a window that looks good:
Here is a window that shows the problem (notice the button on the lower left, and the font size):
I know I can increase the width and add margin to compensate, but I need to understand why this happening.
I am close to a release and I want to make sure my users do not see this effect.
All ideas appreciated.

I'm not running XP right now, but I thought you could customize the size of the text that appears in window captions (and buttons) via the Display Properties (right-click desktop, select Properties, and it's the 3rd or 4th tab, I think). It lets you select colors for selected items, background colors of windows, etc.
That would be separate from setting the DPI settings.

This looks like an unholy XP feature. It had the option to change the size of the system font independently from the video adapter DPI setting. Very convenient to XP users living in Easy Asia where glyphs that make up the letters are very intricate and need all the pixels they can get to make their script legible.
It is covered by Windows Forms with the Form.AutoScaleMode property, which defaults to Font instead of Dpi. WPF is however strongly biased to Dpi, the normal way of scaling.
I don't think the twain shalt ever meet. Tell your user to reset the XP setting. It is buried somewhere in the Control Panel + Display setting, I don't have it anymore to tell you exactly where to look. Or the logical alternative, changing the video DPI setting to match the font size. That's was in the Adapter tab, IIRC. Changing it from 96 to 120 DPI would be a good guess.

Related

Moving development from 100% Windows scaling to 150% chops WinForms window

I use C# Winforms in Visual Studio 2010. Since I've upgraded my laptop from the old 1366 x 768 resolution laptop to a new laptop with a 1920x1080 resolution, I noticed a problem when continuing development on the new laptop. I isolated the issue down to the new 150% Windows OS-wide scaling (Windows on the old laptop used 100% scaling). When I run the program, the right side of the window is strangely chopped off.
Here's the working version on the old laptop (1000 pixels wide, or 1500 pixels in 150% scaled Windows mode):
And here's the new version on the new laptop with the chopped window (1286 pixels wide, when it should be 1500 due to the 150% scaling).
Upon immediately loading the project into the new 150% scaled Windows setup and running the program, it appears to work fine, but as soon as you move one of the buttons so that VS updates the designer code (button 5 was moved as you can see), and then run, the window is chopped.
Even when manually going into the Form1.Designer.cs code, and adjusting the ClientSize to a stupid high horizontal value like ClientSize = new System.Drawing.Size(3000, 709); results in a window width that is limited to 1286 pixels at most. (Not so) coincidentally, 1286 is around 1920 / 1.5.
Basically, what the heck is going on? This appears like a bug with VS's scaling management. To be clear, the problem occurs when moving development from a 100% Windows scaled screen to a 150% Windows scaled screen, on any system. You don't need two laptops to reproduce the problem, it can all be reproduced on a single laptop (but make sure you log out and into Windows after switching from/to 100% or 150%).
Finally, to be clear, I know about setting the DPI-aware setting to true using an app.manifest file. Although this allows clearer text and solves the chopped window problem, I do NOT want to go this route due to inconsistent changes in my program's GUI such as overlapping controls and misplaced items on some setups.
I've found two half-solutions so far:
First is upgrading to Visual Studio 2017 (which allows you to force 100% scaling in VS Forms designer even in 150% Windows scaling)
Second is keeping with an earlier version of Visual Studio (including VS 2010), but making sure Windows is set to 100% scaling. If you've only just changed the scaling setting, make sure to log out and in of Windows to ensure the scaling is applied appropriately.
A relatively simple workaround is to create a Panel Control that is the size you desire for the window, send it to the first layer (right click the control in the designer> send to back). Then set the form to AutoResize to fit that control. (also set AutoSizeMode to GrowAndShrink in case the form appears larger than it should)
This works great if you need Fixed forms but for Resizable forms you might want some extra code that resizes this panel when the form's resize event happens.

Winforms Scaling and Cutting Issue in Screens with Different Resolutions

I have a desktop app that is developer for Windows operating Environment.The App was developed on a 1,280x720 Monitor.It works very well on most systems with normal screen resolutions.Including 1080P and old 17 and 15 inch monitors.
The thing is when it comes to Laptops with 15" screen and 1080P resolution,the App shows up correctly at first but after using a control,the window gets smaller.The Text gets larger and some controls fall on top of others.
Another issue is that when the user has adjusted this size setting to High
The app window gets Cut and it does not show the complete content.The Application is not full screen.
One user was using a Windows Surface Pro and to get the Application Fit,the above setting was reduced.But this made the App too small,so the user ended up getting a refund.
I'm not targeting Tablet(Surface Pro) users.The intended audience is desktop Users.
What is the best way to tackle this issue keeping winforms GUI.
Please advice.
It seems you're looking for the AutoScaleMode property. This will allow your controls to change size according to the zoom level of your users' PCs (which you pictured above).
There is some really good advice in this answer to 'Creating a DPI aware application'. But basically:
Set the AutoScaleMode of your base control (the Form) to Font or Dpi
Remove as many custom font settings from your controls as possible (this will restore them to the default MS Sans Serif at ~8pts)
Develop the app at the standard zoom level and then test it on larger screens with higher zooms, see how it goes.
Hope this helps

Can someone explain in laymans terms what DPI resolution is, and whether it is a characteristic of a monitor or the operating system

I have a Winforms application that is working correctly on various versions of windows and various resolutions. When the application runs on a Motion CL900 tablet, however, the layouts are completely messed up; mainly caused by panel controls that are perfectly sized on other computers now being too small and causing scrollbars. The Motion devices are running Windows 7 Professional.
I have read on a few posts on stackoverflow that Windows machines have a standard DPI of 96, but this device clearly isn't 96 DPI. Is the fact that this device is "non-standard" a result of it's screen or is it caused by a setting in it's OEM version of Windows 7? I have read that I must set AutoScalingDimensions for my form to reflect the DPI of the PC I am developing on. But how do I even know what DPI my machine/screen is that I am developing on?
I have the following in my designer file for the form that has the layout issues:
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
I would appreciate anyone who has had experience with working with Winforms at various DPI resolutions shedding some light on this question, and maybe give some guidelines for .Net developers how to successfully handle non-standard DPIs.
There's indeed two different uses of the term here:
The display device's native resolution. This is actually how many pixels are within 2.54 cm. Larger values mean obviously a clearer, but smaller picture overall.
The OS' scaling of fonts and widgets. 96 dpi is the "native" size for Windows for example. That is, if you have a display that also has 96 dpi, then the controls are the size they should be when you look at them. Also point sizes for fonts are exactly the right size, then. If you have a display with, say, 120 dpi and set the OS to that measure too and then put both side by side you could measure with a ruler and find widgets and fonts in both cases to be the same size.
Nowadays the second measure mostly controls widget size if your eyes are not capable of working with too small controls. And plenty of applications have problems displaying correctly if you change it, although it's far better since Vista.
Dot per inch are related to the monitor/video card/resolution and just means how many points (or pixels) are shown in the length unit (inch).
Clearly is not related to the OS because you can have same values in all OS (Windows, Linux, Mac)...
DPI is dots per inch and it is a setting you can set in your OS. However, it is a characteristic of the monitor.
Since you are on Windows 7, to change DPI settings, you would want to do:
Control Panel
Appearance and Personalization
Display
Set Custom Text Size (DPI) - (on side bar)
Just change it till you get to 96 DPI (100% usually).
Windows 7 has an option in the Display properties called "Set custom text size (DPI)" if this is set to more than 100% it can impact how elements appear in an application, and can cause layout problems. I'd recommend keeping this at 100%, which is 96 DPI in Windows terms.
Note: the actual DPI resolution is determined by your monitor.

Windows XP application (.NET/C#) resize problem

I have a Windows (XP/Vista/7) application implemented in C# using .NET 3.5 and I have a weird resize problems on a small number of Windows XP machines (I haven't been able to reproduce the problem myself).
The application uses a System.Windows.Forms.Form with a System.Windows.Forms.Panel which holds sub-views. Each sub-view is in itself a System.Windows.Forms.Form. During initialization each sub-view is added to the panel (panel.Controls.Add(sub-view)) and the controller selects sub-view by playing with the Hide and Show-methods of each sub-view.
Figure 1 shows how the application normally looks. The panel is the part with the lovely waterdrop-background-image.
But on some Windows XP machines the application looks like figure 2. The entire application has been resized (weird in itself since I have static Max/Min attributes) and the panel is bigger (and has dropped slightly). The background image repeats and any text on the panel is also resized.
Any ideas what this can be? Can it be a .NET-related problem? I do not have access to the problematic machines so all have to go on at the moment is some blurry screenshots.
Update
It is a DPI problem. Changing the DPI setting (on Windows XP) and the application will be resized (but on Vista/7 it stays correct). Thank you for the speedy response guys.
Isn't this a result of DPI settings which was one of the key things WPF tried to address with it's ability to auto-resize, move, wrap, etc?
There are some similar questions around that involve issues caused by changing DPI:
WPF DPI issues
C# Scaling UserControl content to match users Dpi/Font Size
How to prevent font resize when changing the DPI of the system
high DPI problems

.Net controls changing size between computers

I have a wierd problem that i need to work out how to resolve,
I have spent the last couple of weeks working on a project for work on my laptop, but when I open the program on one of the work pcs alot of the controls are the wrong size and over lap etc,
the differences between the machines is this:
Laptop:
Windows 7 Pro;
Display - 1920*1040;
Visiual Studio 2008;
.net framework 3.5
Work Desktop:
windows xp pro;
display: 1024*768;
visual studio 2008;
.net framework 3.5;
to discribe the problem better, i have a panel which i have set to be 300px wide, which has a label inside with the day and the day in the mm-DD-yyyy format, using arial and size 8 font.
On the laptop it all fits perfectly but on the desktop the panel seems smaller and the label only displays half the text.
That is just one of many problems, another is with colour system.control seems to be a completly different colour between systems (althoug I figure that to be a win7 vs xp problem)
What can I do to fix this?
is it a windows version problem? (I have xp on a vmware machine on my laptop so i could code and design in that)
is it a display problem? - this is a big problem for me as i only have 1 laptop and I think this problem could have caused me mark loss on my recent assignment for Uni (I coded on laptop and never opened on a desktop untill today - so had no idea of this problem)
EDIT: I have found a solution of sorts for my particular problem, I discovered that my laptop was working on 125% on the dpi settings for visually impaired (no idea how..) so I have reset it back to 100% or 96Dpi Which has fixed my problems, and after chatting to a couple of other developers I know, they say that they tend to design for 96 dpi while leaving a little bit of white space around text to be safe. but then they don't tend to use c# much and mainly code all in c++ using QT framework.
The video adapter in your workstation has a different dots-per-inch setting. The form automatically rescales itself to accommodate that.
This is going to happen as well when you ship your product and it will run on the client's machine. Changing the form's AutoScaleMode property is not a fix, that will just produce clipped text in the controls. Make sure you form design is resilient to layout changes. Dock, Anchor, TableLayoutPanel, FlowLayoutPanel, the Resize event for tough cases. And make sure the controls inherit their container's Font property (not bold in the Properties window)
Ensure you can resize your panel in Visual Studio with all of the controls inside it being repositioned and resized properly. You can use anchors to achieve this, or perhaps you should use a TableLayoutPanel control instead of a regular Panel.
Change your setting for AutoScaleMode.

Categories

Resources