Centrar Formulario en pantalla
Declare Function glrMoveWindows Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWindth As Long, ByVal nHeight As Long, ByVal bRepair As Long) As Long
Function GetScreenResolution() As String
Dim R As RECT, hwnd As Long, RetVal As Long
hwnd = GetDesktopWindow()
RetVal = GetWindowRect(hwnd, R)
GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
End Function
'Al abrir el formulario y dependiendo de la resolución de la pantalla
Private Sub Form_Open(Cancel As Integer)
Dim posicion As String
If GetScreenResolution = "1024x768" Then
posicion = glrMoveWindows(Me.hwnd, 100, 65, 850, 510, True)
ElseIf GetScreenResolution = "1152x864" Then
posicion = glrMoveWindows(Me.hwnd, 200, 100, 850, 510, True)
Else
posicion = glrMoveWindows(Me.hwnd, 100, -20, 850, 510, True)
End If
End Sub
explicación de las posiciones
posicion = glrMoveWindows(Me.hwnd, 100, 65, 850, 510, True)
100 = posición margen izquierdo
65 = posición margen superior
850 = anchura del formulario
510 = altura del formulario