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

后端 未结 8 577
时光取名叫无心
时光取名叫无心 2020-11-27 19:13

Why is it, that in the Visual Studio WinForms designer I cannot increase the size of my Form above the resolution of the screen I am currently working on? I think it should

8条回答
  •  不知归路
    2020-11-27 19:50

    Deriving from Form, overriding some properties and using interop. This is VB.NET sorry but you get the idea.

    Using the derived form you can use "SizeDesign" and "SizeRuntime" properties for design and runtime respectively.

     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
    

    A.J.

提交回复
热议问题