none
Cómo mostrar un formulario entero en el diseñador con mayor resolución que la pantalla? RRS feed

  • Pregunta

  • Hola compañeros,

    sabeis si se puede mostrar un formulario entero, que tenga más ancho que la resolución de pantalla? El problema es que tengo un formulario que se corta justo en el ancho de pantalla definido en la resolución, y no me permite ver el resto. ¿Hay alguna forma de re-escalarlo, o ver todo?

    Muchas gracias y saludos!

    miércoles, 27 de octubre de 2010 8:58

Respuestas

Todas las respuestas

  • Has probado a habilitar la propiedad AutoScroll del formulario?
    Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
    Si la respuesta te ha sido util Votala.
    Mi Blog: Jtorrecilla
    Enlace a Faq de Winforms en Ingles Muy bueno
    • Marcado como respuesta melgarFernandez miércoles, 27 de octubre de 2010 11:00
    miércoles, 27 de octubre de 2010 9:49
    Moderador
  • Muchas gracias!
    miércoles, 27 de octubre de 2010 11:00
  • Hola juanrafrndz

    Hace tiempo realice un código que redimensionaba automáticamente todos los controles de un formulario, a ver si te sirve:

    Primero crea una clase a parte en tu proyecto:

    Public Class SizeControl
      Public Height As Integer
      Public Width As Integer
      Public Top As Integer
      Public Left As Integer
      Public FontSize As Integer
      Public FontHeight As Integer
      Public Name As String
      Public Sub New(ByVal Name As String)
        Me.Name = Name
      End Sub
    End Class
    

    Y ahora, en tu formulario crea estas variables privadas:

      Private orgHeight As Integer
      Private orgWidth As Integer
      Private HeightPercent As Double
      Private WidthPercent As Double
      Private Title As String
      Private Sizes As Collection = New Collection
      Private ShowResize As Boolean = False
    

    Y estos métodos:

      Private Sub ResizeControls()
        Dim SizeControl As SizeControl
        Dim Font As Font
        For Each Control As Control In Me.Controls
          SizeControl = CType(Sizes(Control.Name), SizeControl)
          If TypeOf Control Is Button Then
            'If Control.Tag.ToString = "txtSize" Then
            '  Control.Height = Me.Controls("txt_Size_").Height
            'Else
            Control.Height = CInt(Math.Round(SizeControl.Height * HeightPercent))
            'End If
          Else
          Control.Height = CInt(Math.Round(SizeControl.Height * HeightPercent))
          End If
          Control.Width = CInt(Math.Round(SizeControl.Width * WidthPercent))
          Control.Top = CInt(Math.Round(SizeControl.Top * HeightPercent))
          Control.Left = CInt(Math.Round(SizeControl.Left * WidthPercent))
          Font = New Font(Control.Font.Name, CInt(Math.Round((SizeControl.FontSize * WidthPercent))))
          Dim HeightRequired As Single = CInt(Math.Round(SizeControl.FontHeight * HeightPercent))
          If Font.Height < HeightRequired Then
    
          End If
          Control.Font = Font
          If TypeOf Control Is Panel Or TypeOf Control Is GroupBox Or TypeOf Control Is TabControl Or TypeOf Control Is TabPage Then
            ResizeChildControls(Control)
          End If
        Next
      End Sub
      Private Sub ResizeChildControls(ByVal parent As Control)
        Dim SizeControl As SizeControl
        Dim Font As Font
        For Each Control As Control In parent.Controls
          SizeControl = CType(Sizes(Control.Name), SizeControl)
          If TypeOf Control Is Button Then
            Try
              If Control.Tag.ToString = "txtSize" Then
                Control.Height = Me.Controls("txt_Size_").Height
              Else
                Control.Height = CInt(Math.Round(SizeControl.Height * HeightPercent))
              End If
            Catch ex As Exception
            End Try
          Else
            Control.Height = CInt(Math.Round(SizeControl.Height * HeightPercent))
          End If
          Control.Width = CInt(Math.Round(SizeControl.Width * WidthPercent))
          Control.Top = CInt(Math.Round(SizeControl.Top * HeightPercent))
          Control.Left = CInt(Math.Round(SizeControl.Left * WidthPercent))
          Font = New Font(Control.Font.Name, CInt(Math.Round((SizeControl.FontSize * WidthPercent))))
          Dim HeightRequired As Single = CInt(Math.Round(SizeControl.FontHeight * HeightPercent))
          If Font.Height < HeightRequired Then
    
          End If
          Control.Font = Font
          If TypeOf Control Is Panel Or TypeOf Control Is GroupBox Or TypeOf Control Is TabControl Or TypeOf Control Is TabPage Then
            ResizeChildControls(Control)
          End If
        Next
      End Sub
    
      Private Sub GetSizes()
        Dim NewSize As SizeControl
        For Each Control As Control In Me.Controls
          NewSize = New SizeControl(Control.Name)
          NewSize.Height = Control.Height
          NewSize.Width = Control.Width
          NewSize.Top = Control.Top
          NewSize.Left = Control.Left
          NewSize.FontSize = CInt(Control.Font.Size)
          NewSize.FontHeight = Control.Font.Height
          Sizes.Add(NewSize, Control.Name)
          If TypeOf Control Is TextBox Or TypeOf Control Is ComboBox Or TypeOf Control Is DateTimePicker Or TypeOf Control Is CheckBox Or TypeOf Control Is RadioButton Then
            If Control.Name <> "COMBO_VISTAS" Then
              AddHandler Control.TextChanged, AddressOf ControlEditado
            End If
          End If
          If TypeOf Control Is TextBox Or TypeOf Control Is ComboBox Then
            Control.BackColor = Color.LightBlue
            Control.ForeColor = Color.Navy
          End If
          AddHandler Control.GotFocus, AddressOf ControlGotFocus
          AddHandler Control.LostFocus, AddressOf ControlLostFocus
          If TypeOf Control Is Panel Or TypeOf Control Is GroupBox Or TypeOf Control Is TabControl Or TypeOf Control Is TabPage Then
            GetChildSizes(Control)
          End If
        Next
      End Sub
    
      Private Sub GetChildSizes(ByVal parent As Control)
        Dim NewSize As SizeControl
        For Each Control As Control In parent.Controls
          NewSize = New SizeControl(Control.Name)
          NewSize.Height = Control.Height
          NewSize.Width = Control.Width
          NewSize.Top = Control.Top
          NewSize.Left = Control.Left
          NewSize.FontSize = CInt(Control.Font.Size)
          NewSize.FontHeight = Control.Font.Height
          Sizes.Add(NewSize, Control.Name)
          If TypeOf Control Is TextBox Or TypeOf Control Is ComboBox Or TypeOf Control Is DateTimePicker Or TypeOf Control Is CheckBox Or TypeOf Control Is RadioButton Then
            If Control.Name <> "COMBO_VISTAS" Then
              AddHandler Control.TextChanged, AddressOf ControlEditado
            End If
          End If
          If TypeOf Control Is TextBox Or TypeOf Control Is ComboBox Then
            Control.BackColor = Color.LightBlue
            Control.ForeColor = Color.Navy
          End If
          AddHandler Control.GotFocus, AddressOf ControlGotFocus
          AddHandler Control.LostFocus, AddressOf ControlLostFocus
          If TypeOf Control Is Panel Or TypeOf Control Is GroupBox Or TypeOf Control Is TabControl Or TypeOf Control Is TabPage Then
            GetChildSizes(Control)
          End If
        Next
      End Sub
    

    Ahora, en el load del formulario, obtienes los tamaños originales de los controles:

      Private Sub frmResize_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        orgHeight = Me.Height
        orgWidth = Me.Width
        Title = Me.Text
        ShowResize = False
        GetSizes()
      End Sub
    

    Con esto tienes la colección de todos los controles del formulario con sus tamaños, ahora le puedes hacer en el propio load un resize al form para ajustarlo al tamaño de la pantalla y controlar los eventos que se disparan para redimensionar de forma unificada los controles:

      Private Sub frmResize_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        If mvarLoadingForm = False Then
          If ShowResize Then
            HeightPercent = 1 / (orgHeight / Me.Height)
            WidthPercent = 1 / (orgWidth / Me.Width)
            ResizeControls()
          End If
        End If
      End Sub
    
      Private Sub frmResize_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ResizeEnd
        If mvarLoadingForm = False Then
          If Not ShowResize Then
            HeightPercent = 1 / (orgHeight / Me.Height)
            WidthPercent = 1 / (orgWidth / Me.Width)
            ResizeControls()
          End If
        End If
      End Sub
    
      Private Sub frmResize_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        If mvarLoadingForm = False Then
          If Not ShowResize Then
            HeightPercent = 1 / (orgHeight / Me.Height)
            WidthPercent = 1 / (orgWidth / Me.Width)
            ResizeControls()
          End If
        End If
      End Sub
    

     Bueno, con todo esto debería funcionarte.

    La verdad es que el código lo tengo metido con mil cosas más y no se si se me pasa algo ahora mismo. Pruebalo y me cuentas, un gran saludo!


    MCTS .NET Framework 3.5 Windows Forms Application Development
    MCTS .NET Framework 3.5 Windows Presentation Foundation
    Visita mi Blog en Geeks.ms
    Sigueme en Twitter
    miércoles, 27 de octubre de 2010 11:53
    Moderador