Newsgroup: it.comp.lang.visual-basic
Titolo: help: gestire frame in base alla risoluzione

devo gestire la larghezza di un frame in base alla risoluzione, si puň fare?
grazie

Ecco una procedura per ridimensionare tutti i controlli (quindi anche il frame) al cambio di risoluzione:
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long,
ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal
dwflags As Long) As Long
       Const CCDEVICENAME = 32
       Const CCFORMNAME = 32
       Const DM_PELSWIDTH = &H80000
       Const DM_PELSHEIGHT = &H100000
Private Type DEVMODE
       dmDeviceName As String * CCDEVICENAME
       dmSpecVersion As Integer
       dmDriverVersion As Integer
       dmSize As Integer
       dmDriverExtra As Integer
       dmFields As Long
       dmOrientation As Integer
       dmPaperSize As Integer
       dmPaperLength As Integer
       dmPaperWidth As Integer
       dmScale As Integer
       dmCopies As Integer
       dmDefaultSource As Integer
       dmPrintQuality As Integer
       dmColor As Integer
       dmDuplex As Integer
       dmYResolution As Integer
       dmTTOption As Integer
       dmCollate As Integer
       dmFormName As String * CCFORMNAME
       dmUnusedPadding As Integer
       dmBitsPerPel As Integer
       dmPelsWidth As Long
       dmPelsHeight As Long
       dmDisplayFlags As Long
       dmDisplayFrequency As Long
End Type
Dim DevM As DEVMODE
Sub ChangeRes(iWidth As Single, iHeight As Single)
       Dim a As Boolean
       Dim i&
       i = 0
              Do
                     a = EnumDisplaySettings(0&, i&, DevM)
                     i = i + 1
              Loop Until (a = False)
       Dim b&
       DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
       DevM.dmPelsWidth = iWidth
       DevM.dmPelsHeight = iHeight
       b = ChangeDisplaySettings(DevM, 1)
End Sub
Sub SetReso(frm As Form, RO!, RV!)
   On Error GoTo ErrH
' dimensione della form
    frm.Width = frm.Width * RO
    frm.Height = frm.Height * RV
' dimensione e posizione dei control
For i = 0 To frm.Controls.Count - 1
    frm.Controls(i).Left = frm.Controls(i).Left * RO
     frm.Controls(i).Top = frm.Controls(i).Top * RV
    frm.Controls(i).Width = frm.Controls(i).Width * RO
    frm.Controls(i).Height = frm.Controls(i).Height * RV
    frm.Controls(i).FontSize = frm.Controls(i).FontSize * RV
Next i
'posizione eventuali linee
   For i = 0 To frm.Linea.Count - 1
      frm.Linea(i).X1 = frm.Linea(i).X1 * RO
      frm.Linea(i).X2 = frm.Linea(i).X2 * RO
      frm.Linea(i).Y1 = frm.Linea(i).Y1 * RV
      frm.Linea(i).Y2 = frm.Linea(i).Y2 * RV
   Next
Exit Sub
ErrH:
    Resume Next
End Sub
A questo punto memorizzo in due variabili i valori di risoluzione attuali:
AttualeX=Screen.Width / Screen.TwipsPerPixelX
AttualeY=Screen.Height / Screen.TwipsPerPixelY
Poi cambio risoluzione:
ChangeRes(1024, 768)
E ridimensiono i controlli:
RapportoOres = (Screen.Width / Screen.TwipsPerPixelX) / AttualeX
RapportoVres = (Screen.Height / Screen.TwipsPerPixelY) / AttualeY
Call SetReso(me, RapportoOres, RapportoVres)
Ciao,
Moreno
#sirri#@
tin.it
(togliete "#" dall'indirizzo)