.Net controls changing size between computers - c#

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.

Related

Visual C# 2015 Form error when moving from 2007 to Win 8

This is a C# winforms project.
This has been driving me crazy for over a week. It would be difficult to show the code, because most of it is generated by visual C itself and it would be quite long.
I have a form quite quite a few controls. The form and the program work just fine on my desktop. When I move to my laptop, which has a lower resolution and which is windows 8, the form, which is taller than the window.
This happens even if I resize the form programatically to fit ahead of time. The form will fit inside the laptop resolution, but half of it would be cut off just as if it ran off of the edge of the screen.
It is important to note,t hat when I set the resolution of my desktop down to the same level as my laptop I so not have this problem. The only different that I can think of is that my desktop is running 2007 and my laptop is running Windows 8. I have tried this on two different win 8 laptops with the same result, but my program has worked on multiple desktops. I do not have a laptop with high enough vertical resolution to contain the form before it is resized via the program.
Is there anything windows 8 does differently in this regard? If so, is there anything I can do to fix it? I am baffled--but it is very important that this program work on my laptop. I designed it to help grade papers, and I need to be able to take it with me.
There are so many controls for my program it would be more than a major undertaking to try to resize them all so that they would fit, by default, at a lower resolution. This is winforms, and because of the way they are laid out grabbing them all and resizing makes half of the controls disappear.
Has anybody else had this problem when moving a program with a large form from win 7 to a win 8 laptop?
Sorry this post is so long, but since it was not reasonable to post the code, I wanted to give a detailed explanation.
I had this happen to me before. What I did was make sure the laptop was in its highest resolution (best quality). Then I played with the resolution to get a close fit. If the resolution is 1228x790 then make sure your form is half the size.
The OS has nothing to do with it. It's a monitor to monitor ratio. Base your app on the laptop resolution instead of the desktop. Then with it smaller you can always maximize the form with the maximize button on the form.
Just be sure to anchor everything properly.
I hope this helps. This is what I always do.

GUI Preview Sizes Issue When Developing WinForm App in Surface Pro 3

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. :)

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

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

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.

C# - Layout problem on Windows XP professional

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).

Categories

Resources