Visual Studio设计器中Form的大小是否仅限于屏幕分辨率?

为什么在Visual Studio WinForms设计器中我不能将我的表单大小增加到我目前正在处理的屏幕分辨率之上? 我认为应该以某种方式开发一种针对较低分辨率系统的更高分辨率的应用程序。 事实上,这将在调试期间剪切表单不应成为问题。 在Visual Studio中可能有一些设置,我似乎无法找到它?

编辑:我的主要问题是我需要能够在具有(例如)1360×768屏幕的笔记本电脑上设计(例如)1440×900尺寸的表格。

不幸的是(我希望其他人会发布一个更好的解决方案!),我所知道的唯一解决方法是在表单中放置一个面板。

将父窗体的AutoscrollAutoSize属性设置为true。 然后将面板尺寸增加到所需的尺寸。 表单本身仍然不会比屏幕分辨率大,但它会显示滚动条,所以至少你可以使用设计器将控制等超出你的尺寸限制放到更大的面板上。

然后,您可能需要添加一些代码以在运行时调整表单大小,以便它足够大以显示没有滚动条的面板(也可能还禁用Autoscroll属性)。

我知道,这不是一个特别好的解决方法……

编辑

看起来这是故意的和设计:

MSDN

Property Form.Size:此属性的最大值受表单运行的屏幕分辨率的限制。 每个屏幕尺寸上的值不能超过12个像素(水平+ 12和垂直+ 12)。

并再次在Microsoft Connect / Public Bug Tracking :

微软于2008年10月9日上午12:18发布

感谢您对.NET Framework的反馈!

您报告的问题实际上是By Design。

在MSDN( http://msdn.microsoft.com/en-us/library/25w4thew.aspx)中 ,您可以在Form.Size属性主题中找到以下信息:

此属性的最大值受表单运行的屏幕分辨率的限制。 每个屏幕尺寸上的值不能超过12个像素(水平+ 12和垂直+ 12)。

因此,我们无法无限扩大我们的forms。 此行为与其他软件(如记事本和Microsoft Paint)一致。

此行为在mothed Form.SetBoundsCore(…)中定义,代码如下:

Size max = SystemInformation.MaxWindowTrackSize;

if(height> max.Height){

 height = max.Height; } 

if(width> max.Width){

 width = max.Width; } 

[…]

谢谢,UIFx团队

编辑2

由于支票在Forms.SetBoundsCore中是硬编码的(使用ILSpy作为反编译器):

 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; } } 

和SetBoundsCore是一个受保护的函数,也许您可​​以尝试从Windows.Forms.Form派生一个类,覆盖SetBoundsCore并且不要在您的SetBoundsCore版本中强制执行此检查? 我没试过,如果它有效…

从Form派生,覆盖一些属性和使用互操作。 这是VB.NET抱歉,但你明白了。

使用派生表单,您可以分别使用“SizeDesign”和“SizeRuntime”属性进行设计和运行时。

  Imports System.Windows.Forms Imports System.ComponentModel Public Class FormEx Inherits Form Private Declare Function MoveWindow Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer, ByVal Repaint As Boolean) As Boolean Private Const DEFAULTSIZE_X = 1024 Private Const DEFAULTSIZE_Y = 768 Protected Overrides Sub OnHandleCreated(e As System.EventArgs) MyBase.OnHandleCreated(e) If mSizeRuntime = System.Drawing.Size.Empty Then SizeRuntime = New System.Drawing.Size(DEFAULTSIZE_X, DEFAULTSIZE_Y) End If If mSizeDesign = System.Drawing.Size.Empty Then SizeDesign = New System.Drawing.Size(DEFAULTSIZE_X, DEFAULTSIZE_Y) End If End Sub  _ Public Shadows Property Size As System.Drawing.Size Private mSizeDesign As System.Drawing.Size = System.Drawing.Size.Empty  _ Public Property SizeDesign As System.Drawing.Size Get Return mSizeDesign End Get Set(value As System.Drawing.Size) mSizeDesign = value If Me.DesignMode Then MoveWindow(Me.Handle, Me.Left, Me.Top, value.Width, value.Height, True) End If End Set End Property Private mSizeRuntime As System.Drawing.Size = System.Drawing.Size.Empty  _ Public Property SizeRuntime As System.Drawing.Size Get Return mSizeRuntime End Get Set(value As System.Drawing.Size) mSizeRuntime = value If Not Me.DesignMode Then MyBase.Size = value End If End Set End Property End Class 

AJ

我找到了解决这个问题的方法。 就我而言,我需要一个设计时解决方案。

我发现使用多显示器系统将桌面扩展到每个显示器,这有效地告诉系统您的最大显示是显示的组合。

这是一种解决方法并且是一种痛苦。 特别适合我,只有一台笔记本电脑在外地。

如果您的目标是多个系统,则可以在运行时进行缩放。 但如果它只是一个目标系统(一个尺寸显示),那么它在设计编码和运行时是不必要的开销。

微软本应该意识到这是一个坏主意,或者至少可以选择覆盖这个“设计function”。

谢谢大家,特别是Ben Schwehn! 使用上面提供的信息,如果您的应用使用基本表单,您可以进行以下更改(在C#中),这将删除从其inheritance的所有表单的限制。

 [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); } 

我找到了一个愚蠢的解决方法,让我可以在设计空间中查看和使用更大的表单大小。

我正在为1240×1024显示器工作1440×900显示器,因此无法到达垂直组件。 我所做的只是右键单击我的桌面,将分辨率更改为1240×1024,调整表单大小,然后更改分辨率。 更换后,它将保留给定的表格大小,即使它超出可接受的限制。

这真正带来的唯一问题是,如果你想在你的第一个分辨率中运行表单,它将太大而无法正常查看。

我知道这是一个老问题,我想我会分享我发现的东西。 快速修复可能会帮助那些人。

这对我有用,复制自

 using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; public class Form1 : Form { [DllImport("User32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int w, int h, bool Repaint); private void Form1_Load(System.Object sender, System.EventArgs e) { this.MaximumSize = new Size(5000, 800); bool Result = MoveWindow(this.Handle, this.Left, this.Top, 5000, 500, true); } public Form1() { Load += Form1_Load; } } 

正如Neil N提到的,您可以在代码中指定它。 但是,如果你想获得屏幕尺寸或分辨率,然后将表格设置为该尺寸,你可以通过Screen.PrimaryScreen.BoundsScreen.PrimaryScreen.BitsPerPixel