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...
Thanks all, especially Ben Schwehn! With the info provided above, if your app uses a base form, you can make the following changes (in C#) which will remove the limitation from all forms inherited from it.
[DllImport("user32.dll", EntryPoint = "MoveWindow")]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int w, int h, bool repaint);
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, height, specified);
MoveWindow(Handle, x, y, width, height, true);
}