I am creating a windows form application in Visual Studio Community 2015. I've built the interface on a 1080p monitor and anchored controls so that when the form is resized, things stay where I want and stretch how I want.
The problem is, I need to try and get this to work on a monitor that is 1024 x 768 and the minimum size of my application is actually larger than that. This causes controls to overlap due to the anchoring and some controls aren't shown at all (they are cut off).
Is there anyway I can easily scale my application to different resolutions automatically?
Related
Visual Studio Experts.
enter image description here
Why is it, that in the Visual Studio WinForms designer I cannot increase the size of my Form above the resolution of the screen I am currently working on? I think it should somehow be possible to develop an application aimed at higher resolutions on a lower res system. The fact that this would clip the Form during debugging should not be an issue. Is there perhaps some setting in Visual Studio for this, which I cannot seem to find?
EDIT: My main issue is that I need to be able to design a (for example) 1440x900 sized form on a laptop with a (for example) 1360x768 screen.
I built an application on a computer with normal DPI size. It is a WinForms application with many forms and custom controls. When I open the project on my Lenovo Yoga 900 with high DPI it looks good in Visual Studio 2013 but when I run the application some parts are off screen.
Even worse is when I open the application after a change on my "normal DPI computer". Most of the controls are scaled up, margins and paddings are scaled too.
With other words my forms are messed up. I've read about the AutoScaleMode which is set to Font. Even I change that property there are not realy noticable changes.
Any suggestions how I can handle that problem? Or does someone have similar experiences/issues?
So here is my form onstartUp event code:
int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;
this.StartPosition = FormStartPosition.Manual;
this.Size = new Size(width, height);
this.WindowState = FormWindowState.Maximized;
the code works fine and the form starts up maximized. After distributing the applications to the user. A user complained and sent a screen shot with the form buttons on the RHS not appearing on the screen!!!
I figured what the problem is, but i don't know how to fix it. The problem is with windows fonts, Control Panel\Appearance and Personalization\Display\ font size on the development machine is small, on the customers it's medium.
how to accommodate for this in code?
The problem is with windows fonts
Not exactly. It is not the font size you are changing, it is the video adapter's dots-per-inch (DPI) setting. The legacy setting is 96 dpi, since Vista it got a lot easier to change this setting. Common other choices are 120 dpi (125%) and 144 dpi (150%), they are directly accessible from the Display applet with a radio button.
Monitor resolutions have been stuck for a very long time, ducking Moore's Law for a good 30 years already. That's finally changing, in no small part due to Apple's push for "retina" displays. The latest MacBook Pro has 2560 x 1600 pixels on a 13 inch screen, about 230 dpi.
That does come with a problem, any program that creates a, say, 1024x768 window has its UI turned into a postage stamp on such a display. The UI just becomes unusable without a magnifying glass. What is needed is for such a program to become aware of the video DPI setting and create a larger window, proportionally larger by the increase of the DPI setting compared to the way the window was originally designed.
This is automatic both in WPF and in Winforms. WPF gets it by default since all of its locations and sizes are expressed in inches, with a unit of 1/96". Winforms still works with pixels, but it has automatic scaling built-in through its AutoScaleMode property.
Which is what is happening on that user's machine, he's got the video DPI setting at a larger value than your machine. However, without also having a larger number of pixels available on his screen. Somewhat typically picked by someone that has a vision impairment, a side-effect of increasing the DPI setting is that fonts get larger and thus easier to read. But with the inevitable problem that any controls that you put near the right and bottom edge of your window are going to fall off, the screen just isn't big enough.
You address this kind of problem by making your window layout adjustable. Or in other words, by making your UI design work with any window size. A very common feature of Windows programs. Just try it on Visual Studio. Drag the bottom right window corner around and observe how it deals with having less space available but still staying usable. Lots of Winforms features to help you doing this, like the Control.Anchor and Dock properties, FlowLayoutPanel and TableLayoutPanel controls, the Resize event for tough cases.
The Q&D fix for this is the Form.AutoScroll property. Set it to True to permit the UI to still be usable, the scrollbars allows the user to still get to controls that are off the window.
The code you posted has nothing to do with the problem. You designed the form in a higher screen resolution than the screen resolution of the user and didn't consider docking/anchoring the controls inside the form.
I have a strange problem. I have designed a windows form application in c# and .net framework 3.5. In the runtime, the form and its controls are fine in all the computers except my laptop, where the controls are not in the correct positions.
If I design the form from scratch on my laptop with correct positioning it will result in an invalid shape for other computers.
My efforts:
If I run the windows in Safe Mode the form size and control positions
are correct.
I have uninstalled the Video Driver and used default windows version but the problem still persists.
I used different frameworks like 2.0 and 4.0, and different Visual Studios versions and they all have the same problems.
Actually all the .net framework product from all the companies indicate the same issue.
My computer Settings:
Laptop 1557 Studio DELL
Graphic ATI Radeon HD 4500
When the text size is artificially increased to 125% text and controls that are rather closely placed will wrap around the form and push everything down/over. If this is something you intend to support, you'll simply have to redesign your form to handle the different enlargement levels you care to support and test those enlarged text modes in your app until you're satisfied with their appearance. It's not something you can strictly control, since increased text size is an accessibility feature.
I assume it is due to a screen resolution differences. I believe that the actual location of the controls is identical in both cases, in one the screen is "larger" and therefor your controls appear in a different position on the screen.
try Designing forms to work on different resolutions and aspect ratios on Windows CE
Another thing you can (and should) do is work with WPF, which is the new way to build user interfaces for windows.
I've found a workaround just now.
In the display settings of Windows 7 I have changed the Text size from 125% to 100%. Everything is smaller but in accurate positions and sizes.
Still wondering how it works!!
Is there any easy way to run an application created in C# on Visual Studio 2005 on any different PC, regardless of its screen resolution?
Screen resolution?
Windows Forms in .NET 2.0 has some mechanisms for dealing with different DPI and it has a better layout system than in .NET 1.1. In general, use layout panels like FlowLayoutPanel, TableLayoutPanel, etc instead of fixing your controls at X/Y coordinates and you'll have a much easier time dealing with different window sizes.
If you can use WPF which I don't recall being applicable to Visual Studio 2005, then you have much more options for resolution independence. The DPI issue goes away and WPF has features such as ViewBox that lets you scale an entire window or control uniformly.