How to set fixed size form to different resolutions - c#

I have a problem and I couldn't find the answer anywhere on the internet. I am working on a project which its forms should be fixedsingle borderstyle. I don't want anyone to maximize or minimize the forms. So the real question is that I have two monitors and I'm working on the bigger one. When I start the program and slide the form to the smaller monitor, it looks exactly the same heigth and width. But I want the form to look smaller as the screen gets small or to look bigger if the screen gets bigger. Can you please help me?

You need to specify the Form.MinimumSize and Form.MaximumSize properties according to your needs. If you want to adjust the form dynamically at run time, you can hook the Form.Move event and set those properties relative to the screen's resolution minus the space used by the taskbar using Screen.WorkingArea. For a better user experience if the form is smaller than the screen size, I recommend disabling the maximize form button by setting Form.MaximizeBox to false.

Related

C# form adjusting screen resolution without sizable

I have created a c# windows forms program with a Form which includes a Diagram, an image and Buttons. When I open the program the Form to big for the computer screen this is because the screen resolution is to big or to small.
How can I make the Form exactly right for each screen resolution type whiteout using sizable?
The problem is because you define (Pixel) sizes for your controls and therefore also your Form.
You can put your space consuming controls (diagrams, images) into Panels and then set the Dock property appropriately (on the controls and/or the panels) so that they scale out to their maximum size. This way you can reduce the size of the Form and because you define ratios rather than pixel numbers the controls/labels will expand as needed.
Depending on how you want it to look like you will have to play with different configurations (one or two controls in one label and then setting dock either to fill or left/right/top/bottom). There's also the SplitContainer control to help you achieve certain design goals.
Additionally, if you always want the perfectly scaled window, open the form in Maximised mode:
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

Scrollbars if form larger than screen

I'm needing some assistance with what I can tell a vendor developing a form in an application I don't have the source to. We've found a bug with one of their large Winforms where if it's opened in an RDP session at 1024x768, the bottom 250px or so of the form which is ~1000px high is unreachable.
They're being difficult about saying there's no solution which I know to be nonsense, but I don't have a Visual Studio environment presently set up to build a proof of concept to test for myself and then show them otherwise.
From what I can tell from other StackOverflow questions and MSDN documentation pages, something like the following should resolve the problem so the form will auto-size to the maximum displayable height then put a vertical scrollbar in to allow viewing the bottom part of the form. Will the following achieve my goal?
public MyTallForm()
{
InitializeComponent();
this.AutoScroll = true
this.AutoSize = true
}
AutoSize responds to change in controls inside the form by growing & shrinking the form as needed.
AutoScroll responds to change in controls inside the form by displaying/hiding the scrollbars.
Thus, AutoScroll won't be activated if AutoSize is active since the form is always large enough. If the problem is from too small display resolution, you'll want AutoScroll.
If the form kept open between RDP sessions, you might need to subscribe to DisplaySettingsChanged to be aware of resolution changes, and either simply Maximize (not sure if it's already maximized, toggling to Minimized and back to Maximized perhaps?) or use GetWorkingArea if you need detailed size.
Set AutoScroll = True and AutoScaleMode to Dpi In Form Properties
Hope it helps.

Keep form and controls proportion deployng a c# application for any screen size

I know this is an "already heard" problem: I have searched a lot but I did not find anything that cleared my mind.
I am developing a c# application with a GUI containing some controls like buttons (made with images) and text.
I developed it setting the main form size to 800x600 but now I need the application to work also on a 1920x1080 screen.
Two problems:
If I position a button near the top-right corner of the main form and set AnchorStyles to Top-Right, when I switch to the big screen, the button is (in proportion) much more close to top-left corner than in the little screen (because the anchor keeps the distance from the border). Is there a way to set a proportional distance from the border?
How can I scale the dimensions of the controls proportionally to the screen size? Shall I use AutoScaleMode like suggested here?
There is a way to add a capability to a form at design time - the ToolTip control does it, that makes properties available to every control on a form. These are called "Extender Providers"
http://msdn.microsoft.com/en-us/library/ms171836
You would want to look at the controls, and cache their sizes and fonts at design time, and the size of the form.
The provider would hang off the form.SizeChanged event at run time. When the size changes, you use the new and original (design time) sizes of the form to calculate and X and Y ratio. You then go through each control and use it's design time size and the ratios to determine its new size and font size. This can get flaky if you allow the user to select sizes that are not the same aspect ratio as your original.
Anyway, that is how it was done in Delphi, and everyone knows if you can do it in Delphi, you can do it in C# :)

Windows Forms: Auto Scale Application

I have a WinForms Application that was designed to support Full HD resolutions (so 1920x1080). Now this App is also supposed to run on a lower resolution: 1600x900.
Is there a way to let the application auto scale itself to fit the lower resolution? Like you would just downscale an image, basically resizing and relocating each control.
My current forms and panels have set their size to 1900x1080, so they just extend out of the screen on the lower resolution.
I have played around with AutoScaleModes and AutoSize, but the best I could get were Scrollbars so that you at least navigate through the forms. Is such a thing as downscaling an application even possible (retaining dimensions/ relative sizes and positions of the controls)?
Thanks in advance for any inputs on this!
If your main form starts in a maximized mode, it will adjust its size automagically.
But (and this is a huge "but" according to your question): the inner controls won't be scaled as you would see on a smartphone. WinForm is not "vector based" as WPF. If you have a fully loaded form in 1920x1080, when the main form is sized down, the controls won't fit and you will get scrollbars.
So the answer is: No.
The solution is available.
Form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
and
Make all control autosize = false.
make a suitable size of your wish.
The property you are looking for is called Dock, it's a property of the controls.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock(v=vs.110).aspx
This basically tells the control how to fill the available space.
Creating a resolution independent application is not a simple logic. Everything in the window should be resize as per the selected resolution. Not only controls' size you have to change the font size also as per the changes. Here is the example how to create a resolution independent form using C# code. Another way is use DevExpress Tool. This tool provides Layout Countrol Container. You can place each control in separate layout item and assign the minimum and maximum size of control.

c# - easy way to get maximum window x/y bounds?

I have a custom styled transparent window and i've seen a lot of issues handling min/max/resize behavior when you use transparency and "WindowStyle=None".
When I tell my window to change it's windowstate to maximized it doesn't get it right so I want to override the logic there. It gets the width right but the height is all messed up and it doesn't know to add padding to account for a outerglow effect.
Without using win32 functions is there a SOMEWHAT EASY way for me to determine the "max viewport" or "max bounds" of the display that the application is running on top of? I think the short answer to this question is probably no but I figured I would ask anyways. I have my min/max width and height set up for the application and I figured if there was some function I could call to bring me back a x/y max bound then I could just set the window height and width to those values after I subtract the padding. My intention is to have supported resolution from 1024x768 - 1920x1080 so that this application can be displayed multiple places without reconfiguration.
Take a look at the Screen.PrimaryScreen Property. It has a method called GetWorkingArea which I think is what you want.
If there is more than one display, then there are methods to enumerate through the displays and find out which display the application is on.

Categories