Is the Size of a Form in Visual Studio Designer Limited to Screen Resolution

Is the size of a Form in Visual Studio designer limited to screen resolution?

Unfortunately (I hope someone else will post a better solution!), the only workaround I'm aware of is to place a panel inside the form.

Set the Autoscroll and AutoSize properties of the Parent Form to true. Then increase the panel size to the desired size. The form itself will still not get any larger than your screen resolution, but it will show scroll bars, so at least you can use the designer to drop controls etc beyond your size limitations onto the larger panel.

Then, you may need to add some code to adjust the the forms size at run-time so that it is large enough to show the panel without scroll bars (and perhaps also disable the Autoscroll property).

I know, It's not a particularly nice workaround...

EDIT:

Looks like this is intentional and by design:

MSDN

Property Form.Size:
The maximum value of this property is limited by
the resolution of the screen on which the form runs. The value cannot
be greater than 12 pixels over each screen dimension (horizontal + 12
and vertical + 12).

and again at Microsoft Connect/Public Bug Tracking:

Posted by Microsoft on 10/9/2008 at 12:18 AM

Thanks for your feedback
on the .NET Framework!

The issue that you have reported is actually By Design.

In MSDN at http://msdn.microsoft.com/en-us/library/25w4thew.aspx, you
can find the following information at the topic Form.Size Property:

The maximum value of this property is limited by the resolution of the
screen on which the form runs. The value cannot be greater than 12
pixels over each screen dimension (horizontal + 12 and vertical + 12).

Therefore, we can't enlarge our forms indefinitely. This behavior is
consistent with other software, such as Notepad and Microsoft Paint.

This behavior is defined in the mothed Form.SetBoundsCore(...) with
the following code:

Size max = SystemInformation.MaxWindowTrackSize;

if (height > max.Height) {

height = max.Height; }

if (width > max.Width) {

width = max.Width; }

[...]

Thanks, UIFx Team

EDIT2:

Since the check is hardcoded in Forms.SetBoundsCore like (using ILSpy as a decompiler):

if (this.WindowState == FormWindowState.Normal && (base.Height != height || base.Width != width))
{
Size maxWindowTrackSize = SystemInformation.MaxWindowTrackSize;
if (height > maxWindowTrackSize.Height)
{
height = maxWindowTrackSize.Height;
}
if (width > maxWindowTrackSize.Width)
{
width = maxWindowTrackSize.Width;
}
}

and SetBoundsCore is a protected function, perhaps you could try deriving a class from Windows.Forms.Form, override SetBoundsCore and don't enforce this check in your version of SetBoundsCore? I haven't tried if it works though...

VS2010 form size and screen resolution issue

You can use that if You need more space. This will create big panel with scrollbars. You cannot set the window size to be bigger then screen.

public Form1()
{
InitializeComponent();
this.AutoScroll = true;
this.AutoSize = true;
this.Controls.Add(new Panel() { Width = 2300, Height = 2000 });
//this one will only set window size to size of screen
this.ClientSize = new System.Drawing.Size(2300, 2000);
}

EDIT:

You can do the same thing in design. Just set form autoscroll to true, drop panel and set it size to huge. That will let You design Your huge panel with usage of scrollbars.

How to autosize the form window based on screen resolution during run time (Where the size of the window created during design is too large)

Setting the WindowState = Maximized will cause the window to open to the full extents of the screen resolution. It doesn't matter what that value is, it will match it.

Sample Image

Edit:
From your comments, it sounds like you want what the AutoSize property will accomplish. I updated the form to add some controls and set the AutoSize = True and the AutoSizeMode = GrowAndShrink. Between these three properties, you should be able to get the form to do exactly what you wish. The one thing to pay attention to is the full extents of your controls within the form. From this picture you can see the form during runtime will resize to fit both text boxes while in the editor, I shrunk the form to hide almost everything. Please also note that in the example below, I set the WindowState = Normal.

Sample Image

Designer automatically re-sizes form when certain properties are set

I see it, this should be a bug in any VS version. It is caused by the ShowIcon property, the designer doesn't handle it correctly when you set it to False. At issue is a bit of code in the Form class that looks like this:

       FormBorderStyle borderStyle = FormBorderStyle;
if (!ShowIcon &&
(borderStyle == FormBorderStyle.Sizable ||
borderStyle == FormBorderStyle.Fixed3D ||
borderStyle == FormBorderStyle.FixedSingle))
{
cp.ExStyle |= NativeMethods.WS_EX_DLGMODALFRAME;
}

In other words, when ShowIcon is False then it uses a different border style from WS_BORDER, it uses the one of a modal dialog. Which has different borders on older Windows versions, they are fatter. Not exactly sure what inspired this code, probably has something to do with Windows 98.

Problem is, the Size property is a calculated value, the Winforms designer only stores the ClientSize property. So when ShowIcon is False then it should redo this calculation, it doesn't.

You can report the bug at connect.microsoft.com but the odds that Microsoft is going to fix it are exceedingly low so it would probably be a waste of your time. There is a very simple workaround for it, instead of setting ShowIcon to False in the Properties window, do it in the constructor instead. Like this:

    public Form1() {
InitializeComponent();
this.ShowIcon = false;
}

Windows Form size issue on different resolutions

The issue here is more likely that it is not working the way you expect. In WinForms development, when you design a form you are actually setting its size. This follows a function of default font size on the machine the form is being displayed on and does not directly correlate to the resolution on the display in question. So, if you design a large form with many controls or large controls, it may display fine at a high resolution but not at a low one. For a better feel of this sizing, take a look at your Form1.Designer.cs file and you will see size values being set for the controls. These sizes do not equate to pixels, but they should give you a relative sizing. You should probably also research dialog units on MSDN or elsewhere.

You could write some code to react to that resolution in the form load event, but in the end the size will be partially constrained by the number of widgets that you need to display. If you had a multi-line edit field, grid control, tree control or some other large widget, you could automatically resize it based on the current display resolution and resize the window at the same time. But that is an application specific decision based on your needs, that is why windows does not try to automatically resize for you.

As noted above, WPF gives a more flexible form definition model and can be more reactive to realign widgets, but in the end if your form is busy enough, a WPF form have the same issues on a lower resolution.

Windows Forms app looks different from Visual Studio designer view

The resolution differences looks like a DPI issue. Windows Forms doesn't scale well to a DPI other than 100%. Check your monitor settings.
In Windows 10, this is labelled "Change the size of text, apps, and other items" in Display Settings.



Related Topics



Leave a reply



Submit