Notifications
Clear all

Auto dimensionar Form - Excel VBA

8 Posts
2 Usuários
0 Reactions
2,092 Visualizações
(@depoisteconto)
Posts: 183
Reputable Member
Topic starter
 

Colegas, boa noite!

Alguem saberia dizer como dimensionar o formulário de acordo com o monitor de cada computador. Até onde pesquisei pude ver que são necessários API's do Windows, mas nenhuma sugestão de código.

Não faço a mínima idéia.

Excel 2007
Windows XP

Qualquer contribuição será bem vinda.

At

 
Postado : 21/08/2012 3:10 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Veja em:
http://www.andypope.info/vba/Anchor.htm
Att

 
Postado : 21/08/2012 5:57 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Segue um modelo que peguei na net, já a alugum tempo, porem ainda não testei aplicar; o autor é Stephen Bullen, pode ser que lhe auxilie

 
Postado : 22/08/2012 6:13 am
(@depoisteconto)
Posts: 183
Reputable Member
Topic starter
 

Verifiquei as alternativas sugeridas pelos colegas, mas nenhuma delas se apliaca a minha solicitação.

Agradeço as sugestões.

At

 
Postado : 22/08/2012 3:07 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Tente adaptar...

Declare Function GetSystemMetrics32 Lib "user32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
 
Declare Function GetSystemMetrics16 Lib "user" _
Alias "GetSystemMetrics" (ByVal nIndex As Integer) As Integer
 
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
 
Sub DisplayVideoInfo()
     
    Dim zmRatio As Variant
     
    On Error Resume Next
     
    If Left(Application.Version, 1) = 5 Then
        vidwidth = GetSystemMetrics16(SM_CXSCREEN)
        vidHeight = GetSystemMetrics16(SM_CYSCREEN)
    Else
        vidwidth = GetSystemMetrics32(SM_CXSCREEN)
        vidHeight = GetSystemMetrics32(SM_CYSCREEN)
    End If
     
    If vidwidth = 800 Then
        ActiveWindow.Zoom = 78
    ElseIf vidwidth = 1024 Then
        ActiveWindow.Zoom = 100
    ElseIf vidwidth = 1152 Then
        ActiveWindow.Zoom = 111
    End If
     
End Sub

..Ou

Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _
    ByVal nIndex As Long) As Long

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _
    ByVal hdc As Long) As Long
  
Function ScreenResolution() As String
    ' Returns the PC's Screen Resolution, such as "800x600".
    '
    ' -- Mike_R 2004 0505
    
    Dim lRval As Long
    Dim lDc As Long
    Dim lHSize As Long
    Dim lVSize As Long
    Const Resolution_Horz = 8
    Const Resolution_Vert = 10

    lDc = GetDC(0&)
    lHSize = GetDeviceCaps(lDc, Resolution_Horz)
    lVSize = GetDeviceCaps(lDc, Resolution_Vert)
    lRval = ReleaseDC(0, lDc)
    
    ScreenResolution = CStr(lHSize & "x" & lVSize)
End Function
 
Postado : 22/08/2012 5:45 pm
(@depoisteconto)
Posts: 183
Reputable Member
Topic starter
 

Caro alexandre, bom dia!

Quais são os eventos para os códigos abaixo?

No primeiro exemplo eu coloquei tudo em um módulo e no evento initialize do form chamei a Sub DisplayVideoInfo. É isso mesmo? Aqui não alterou nada.

At

Boa noite!!

Tente adaptar...

Declare Function GetSystemMetrics32 Lib "user32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
 
Declare Function GetSystemMetrics16 Lib "user" _
Alias "GetSystemMetrics" (ByVal nIndex As Integer) As Integer
 
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
 
Sub DisplayVideoInfo()
     
    Dim zmRatio As Variant
     
    On Error Resume Next
     
    If Left(Application.Version, 1) = 5 Then
        vidwidth = GetSystemMetrics16(SM_CXSCREEN)
        vidHeight = GetSystemMetrics16(SM_CYSCREEN)
    Else
        vidwidth = GetSystemMetrics32(SM_CXSCREEN)
        vidHeight = GetSystemMetrics32(SM_CYSCREEN)
    End If
     
    If vidwidth = 800 Then
        ActiveWindow.Zoom = 78
    ElseIf vidwidth = 1024 Then
        ActiveWindow.Zoom = 100
    ElseIf vidwidth = 1152 Then
        ActiveWindow.Zoom = 111
    End If
     
End Sub

..Ou

Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _
    ByVal nIndex As Long) As Long

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _
    ByVal hdc As Long) As Long
  
Function ScreenResolution() As String
    ' Returns the PC's Screen Resolution, such as "800x600".
    '
    ' -- Mike_R 2004 0505
    
    Dim lRval As Long
    Dim lDc As Long
    Dim lHSize As Long
    Dim lVSize As Long
    Const Resolution_Horz = 8
    Const Resolution_Vert = 10

    lDc = GetDC(0&)
    lHSize = GetDeviceCaps(lDc, Resolution_Horz)
    lVSize = GetDeviceCaps(lDc, Resolution_Vert)
    lRval = ReleaseDC(0, lDc)
    
    ScreenResolution = CStr(lHSize & "x" & lVSize)
End Function
 
Postado : 23/08/2012 5:26 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Para o segundo caso leia: http://www.xtremevbtalk.com/showthread.php?t=165267

Veja também:
http://visualbasic.ittoolbox.com/groups ... ize-165942

;)

 
Postado : 23/08/2012 5:47 am
(@depoisteconto)
Posts: 183
Reputable Member
Topic starter
 

Alexandre, agradeço a boa vontade e as sugestões, mas não consegui entender nenhum dos links. Pensei por uns intantes também sobre a relevância desse procedimento para o dia a dia. Vou ajustar meu form principal suficiente para caber em uma tela de 800x600 e só.

Pensei em alto dimensionar porque a resolução do meu pc é de 1280 x 1024 mas outros 2 computadores na empresa não atingem essa resolução. O resultado é que para o meu computador eu poderia expandir mais o tamanho do meu form, permitindo adição de controles, etc. Hoje se eu o fizer, certamente não aparecerá nos computadores dos colegas.

Esse negócio não é simples.

At

 
Postado : 23/08/2012 8:53 am