IDE: Visual Studio 2010, C#.net 4.0 winforms application
My project is build on 1366x768 screen resolution and running fine on it, this application rich of of winforms and user controls and custom controls.
Problem #1:
How to handle, When I run the same application on smaller resolution for eg. (1200x800) The right part of application is not visible on that screen.
Problem #2:
How to handle, when I run the same application on bigger resolution screen for eg. 1920x1080, the controls are stretching non proportionally,
for problem 2, please tell me how to prevent controls from stretching and changing its location, I have observed that the location and size of control is changed, which I don't want, can you suggest me how to handle this problem.
also provide me a generic solution for #1 and #2, I have searched that anchor and dock is one way to handle it but still I am not satisfied with those solutions because of having rich of controls on it.
Related
I have written a program in C# (Visual Studio) which makes use of multiple forms. The problem occurs whenever the program is run on a different computer which has a different screen resolution. The contents of the form do not fit into the form whenever the program is run on a computer with a smaller screen resolution. What can I do to make the CONTENTS of the form resize accordingly, depending on the screen resolution so that the contents of the form will always fit, irrelevant of the screen resolution/size of the computer on which it is being run?
Thanks a lot!
Assuming you are using WinForms, your best bet in this case is to make use of the various container controls included in the framework, like the FLowLayoutPanel and TableLayoutPanel.
If you want to avoid these, use the standard Panel control and make use of Dock property to ensure it fills the required areas correctly. Then use the Dock property on all your controls to make the layout more responsive to different resolutions, and more importantly different DPI settings in Windows.
I have an application designed in visual C# that is about a quarter of a normal computer screen. The reason its that small is because its easier to work with in Visual Studio. However, I would prefer if when I run it, it maximizes to the full screen. I tried this in my Main_Load:
this.WindowState = FormWindowState.Maximized;
This causes the window itself to maximize, but the application itself is still quarter of the screen. Is there a way to maximize the application itself, and not just the window?
I am guessing you have not docked or anchored any of the controls, meaning they will not move when the window is resized.
Have a look at docking here: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock(v=vs.110).aspx
And have a look at anchoring controls here: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor(v=vs.110).aspx
Both pages should help you understand how to make controls resize with the window.
Either you change the size of your application window in the visual studio designer so it fits your personal screen (bad idea), or you make your application aware of window size and window size changes and actively scale parts of the GUI programmatically (better).
If WinForms, as others have stated, you need to Anchor and/or Dock your controls so they know how to resize in relation to the Form when the Form size changes. These will work for simple layouts.
For more complicated needs, however, check out the TableLayoutPanel and/or the FlowLayoutPanel.
A robust User Interface is probably going to be using all of these elements in one way or another...
I know there will be folks who will vote this question down or ask for close. But if there is any kind of information or code I can provide you to know more about my program I will let you know. So please keep reading and see if you have had a similar problem.
I am running a Win7 64bit with .Net Framework ver 4.5.
I have created a Winform application. And to create my form elements I have taken advantage of a library called Metroframework that gives the program a metro look and feel. It contains some standard controls and as well as user controls that inherit from the original Form class. This is the opening view of my program.
However, for some strange reason, when I came to install my program on two other computers (one running Win7 and the other Win8), I noticed that some of my form elements have changed their location and some have just disappeared or just have been displaced. This has frightened me knowing the amount of time I have spent to put this elements in place.
Everything looks fine on my own computer both in dev environment and after building my application in release version. At first I thought this is a screen resolution problem on the other two devices, but that was not the case either. And even if it was, why should this happen?
Can anyone please help me solve this problem? I will share any part of my code you need. But I really have no idea where the source of this problem is!
The main influence on the layout variations on different machines is theForm.AutoScaleModeproperty.
In theory the default setting should work fine but I found that sometimes it is best to switch it off completely, that is going from Dpi or Font to None..
MSDN explains a little about the intended effect.
BTW: The is also a ContainerControl.AutoScaleMode property, so you could choose different modes for some parts of your forms as described here:
The AutoScaleMode property specifies the current automatic scaling
mode of this control. Scaling by Font is useful if you want to have a
control or form stretch or shrink according to the size of the fonts
in the operating system, and should be used when the absolute size of
the control or form does not matter. Scaling by Dpi is useful when you
want to size a control or form relative to the screen. For example,
you may want to use dots per inch (DPI) scaling on a control
displaying a chart or other graphic so that it always occupies a
certain percentage of the screen.
To remain true to the pixel-precise layout use:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
The last value in the AutoScaleMode enumeration is Inherited which most often would be chosen for nested containers.
Update: The choice of ContainerControlsis rather limited:
System.Windows.Forms.Form
System.Windows.Forms.PropertyGrid
System.Windows.Forms.SplitContainer
System.Windows.Forms.ToolStripContainer
System.Windows.Forms.ToolStripPanel
System.Windows.Forms.UpDownBase
System.Windows.Forms.UserControl
Maybe the most useful is the UserControl. Note that it doesn't expose the AutoScale property in its instances but only in the class definition. Also note that you can't add controls to an instance in the desiger, but you could assemble them in maybe a Panel and then set a UserControl (with AutoScale=Font) to be the Panel's Parent.. You'll need to allow for some extra space in any case, though..
This question already has answers here:
.Net controls changing size between computers
(3 answers)
Closed 9 years ago.
First time i'm developing a Windows Form Application with C# . I'm using Visual Studio 2012.
My form's size = 1096x508. Also i set Minimum Size and Maximum Size properties to 1096x508 .
This is screenshot of my app ,
But when i execute this app on another computer, result like this :
As you see, red line (at bottom of app) invisible. Because applciation's height is 508 px (as expected) on my pc but 416px on other computer. Because of this , red line staying out of Form. So we couldn't see it.
In shortly, my Form's size 1096x508px but it's only 823x416px on another computer. Can you tell me why there are difference? And how can i fix this? There are resolution difference between this screens.
The behaviour of your application on those computers may be caused by different dpi (dot-per-inch) settings of the Windows operating system. In order to check that please compare the actuals values in Windows display settings (100%, 125%, ...).
If you want to have your program independent from dpi settings you may try to work with different panels (control containers). Your status bar could have a fixed with, while the game area is a docked panel (filling the remaining space).
In general, staying independent from actual dpi, is a difficult topic. Most of the time you can work with autosizing controls, but you could run out of space if, say, two labels overlay.
The main issue, as you have already discovered, is that computers with a different DPI setting will cause the controls to scale.
What Hans was suggesting in his linked answer is that you need to re-design your form so when it gets re-size messages it will handle them accordingly.
The main way this is normally handled is setting the Anchor property or the Dock property of a control. By default a control will anchor to the top left corner of it's parent container. When it is told to scale it scales down and to the right. By changing the anchor point to be the bottom only it will make your bottom control move up instead of moving down off of the boundaries of the parent.
I made custom borders for my application, like the VisualStudio 2012
There is one central mainform and 4 smaller, dynamically positioned border forms.
In the mainform I have overidden the events OnMove, OnSizeChanged, OnActivate, OnDeactivate.
In those events I set the location, size and color of the borders.
It works quite nicely, but there is some awful artifacts!
Those are the same artifacts that appear when resizing ANY window.
I made a video with my application to show what kind of atrifacts I mean.
Those appear when moving or resizing the window.
Obviously this problem IS solveable, because VisualStudio2012 does it too (meaning that it doesn't have the problem. Just try it, resize the VS2012 window, it won't flicker)
In my implementation I used the same way that VS2012 uses: 4 layered windows that make up the border of the form.
In case someone doesn't the glitches I'm talking about. Here's the video:
http://youtu.be/kKiPke8ruaI
What I need is a way to "synchronously" set the location and size of the 4 border windows.