Visual Studio设计器中窗体的大小是否受屏幕分辨率的限制

本文关键字:是否 屏幕 分辨率 Visual 窗体 Studio | 更新日期: 2023-09-27 18:01:40

为什么在Visual Studio WinForms设计器中,我不能将窗体的大小增加到我目前正在处理的屏幕分辨率以上?我认为在低分辨率的系统上开发一个高分辨率的应用程序应该是可行的。这将在调试期间剪辑Form的事实不应该是一个问题。也许在Visual Studio中有一些设置,我似乎找不到?

编辑:我的主要问题是,我需要能够在笔记本电脑上设计一个(例如)1440x900大小的表单(例如)1360x768屏幕。

Visual Studio设计器中窗体的大小是否受屏幕分辨率的限制

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

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

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

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

编辑:

看起来这是有意设计的:

MSDN

财产形式。大小:此属性的最大值受表单运行所在屏幕的分辨率。值不能。每个屏幕尺寸大于12像素(水平+ 12)和垂直+ 12).

和在Microsoft Connect/Public Bug Tracking:

由Microsoft于10/9/2008 at 12:18 AM发布

谢谢你的反馈在。net框架上!

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

在http://msdn.microsoft.com/en-us/library/25w4thew.aspx的MSDN中,您可以在主题表格中找到以下信息。大小属性:

此属性的最大值受对象的分辨率的限制窗体在其中运行的屏幕。取值不能大于12每个屏幕尺寸的像素(水平+ 12和垂直+ 12)。

因此,我们不能无限地扩大我们的形式。这种行为是与其他软件一致,如Notepad和Microsoft Paint。

这个行为是在Form.SetBoundsCore(…)中定义的以下代码:

Size max = SystemInformation.MaxWindowTrackSize;

if (height> max.Height) {

height = max.Height; }

if (width> max.Width) {

width = max.Width; }

[…]

谢谢,UIFx团队

EDIT2 :

因为检查是硬编码在表单中。SetBoundsCore like(使用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派生一个类。表单,重写SetBoundsCore和不强制这个检查在你的版本的SetBoundsCore?我还没有试过它是否有效……

感谢大家,尤其是Ben Schwehn!有了上面提供的信息,如果你的应用程序使用基本表单,你可以做以下改变(在c#中),这将从所有从它继承的表单中删除限制。

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

这对我有用,复制自

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

从Form派生,重写一些属性并使用互操作。这是VB。。NET,抱歉,但你懂的。

使用派生形式,你可以使用"SizeDesign"answers"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
    <Browsable(False)> _
    Public Shadows Property Size As System.Drawing.Size
    Private mSizeDesign As System.Drawing.Size = System.Drawing.Size.Empty
    <Category("Layout"), _
    Description("Sets the size of the form at design time."), _
    RefreshProperties(RefreshProperties.All)> _
    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
    <Category("Layout"), _
    Description("Sets the size of the form at runtime."), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    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

A.J.

我已经找到了解决这个问题的方法。在我的情况下,我需要一个设计时的解决方案。

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

这是一个工作,是一个痛苦。特别是对我来说,当我在外地只有一台笔记本电脑。

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

微软应该意识到这是一个坏主意,或者至少可以选择重写这个"设计特性"。

我发现了一个愚蠢的解决方案,可以让我在设计空间中查看和使用较大的表单尺寸。

我正在为1240x1024显示器安装1440x900显示器,因此无法到达垂直组件。我所做的只是右键单击桌面,将分辨率更改为1240x1024,调整表单大小,然后将分辨率更改回来。在更改后,它将保持给定的表单大小,即使它超出了可接受的限制。

唯一的问题是,如果你想在你的第一分辨率下运行表单,它会太大而无法正常查看。

我知道这是一个古老的问题,我想我应该分享我的发现。这个权宜之计也许能帮到别人。

我正在设计一个使用1080x1920垂直屏幕的设计。有时我需要在另一台没有垂直屏幕的机器上制作主表单。每次在主表单上工作时,表单分辨率都被强制设置为1080x1109。真痛苦。我唯一能做的就是做一些改变,然后使用Windows多屏幕来改变桌面,使一个显示器在另一个显示器之上。然后扩展设计窗口以跨越2个监视器,然后手动更改表单的大小。这个"特性"不可能不是一个bug。

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