SHARE
TWEET

Untitled

a guest Aug 28th, 2019 80 in 124 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '
  2. ' CentralizeForm
  3. '
  4. Private Sub CentralizeForm()
  5.     Dim ID As Integer
  6.     Dim X As Double
  7.     Dim Y As Double
  8.     Dim pt As POINTAPI
  9.    
  10.     GetCursorPos pt
  11.    
  12.     On Error GoTo ErrorHandler:
  13.    
  14.     ' Retorna resolucao width x height px do monitor onde o mouse esta posicionado.
  15.    X = GetSystemMetrics(0)
  16.     Y = GetSystemMetrics(1)
  17.    
  18.     ID = IIf(pt.X > X, 2, 1)
  19.    
  20.     If ID = 2 Then
  21.         optMonitor1.Value = False
  22.         optMonitor2.Value = True
  23.         optMonitor2.SetFocus
  24.     End If
  25.    
  26.     ' Posicao manual do form.
  27.    Me.StartUpPosition = 0
  28.  
  29.     ' Transforma px em ppi, unidade de medida utilizada pelo UserForm.
  30.    X = (PixelsToPoints(X) / 2) + ((ID - 1) * PixelsToPoints(X))
  31.     Y = (PixelsToPoints(Y) / 2)
  32.    
  33.     ' Posiciona o form para abrir centralizado na tela chamadora.
  34.    Me.Left = CSng(X) - Me.Width / 2
  35.     Me.Top = CSng(Y) - Me.Height / 2
  36.    
  37.     Exit Sub
  38. ErrorHandler:
  39.     Debug.Print Err, Err.Description
  40.     Select Case Err
  41.         Case -2147200630, 91
  42.             ID = 2
  43.             Resume Next
  44.     End Select
  45. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top