Public Sub Posit(ByVal Obj As Object, Optional ByVal X As Double, Optional ByVal Y As Double)
Rem. ——— Vous pouvez au préalable positionner l'UserForm par rapport à quelque chose.
' Obj: Ce par rapport à quoi vous voulez le positionner. X et Y indiqueront comment :
' X: -1: Collé au coté gauche, 0: Centré horizontalement, 1: Collé au coté droit.
' Y: -1: Collé au bord supérieur, 0: Centré verticalement, 1: Collé juste en dessous.
' D'autres valeurs entraineront un recouvrement partiel ou un certain éloignement.
' Mais rien ne vous empêche de rectifier encore ensuite la propriété Left ou Top
' de l'UFmCalend pour ajouter un interstice en points au bord de l'objet. Mais toujours
' avant le Show, donc avant utilisation de la méthode Saisie.
' X et Y sont facultatifs et assumés = 0. Il est donc centré sur l'objet Obj si non précisés.
Dim G As Double, D As Double, H As Double, B As Double, U As Object, K As Double, Z As Double
If TypeOf Obj Is MSForms.Control Then
G = Obj.Left: H = Obj.Top: Set U = Obj.Parent
Do: K = (U.Width - U.InsideWidth) / 2
G = G + U.Left + K: H = H + U.Top + U.Height - U.InsideHeight - K
If Not TypeOf U Is MSForms.Frame Then Exit Do
Set U = U.Parent: Loop
D = G + Obj.Width: B = H + Obj.Height
Else
Z = ActiveWindow.Zoom / 100
K = GetDeviceCaps(GetDC(0), 88) / 72
G = ActiveWindow.PointsToScreenPixelsX(Obj.Left * K * Z) / K
D = ActiveWindow.PointsToScreenPixelsX((Obj.Left + Obj.Width) * K * Z) / K
K = GetDeviceCaps(GetDC(0), 90) / 72
H = ActiveWindow.PointsToScreenPixelsY(Obj.Top * K * Z) / K
B = ActiveWindow.PointsToScreenPixelsY((Obj.Top + Obj.Height) * K * Z) / K
End If
Me.Left = (X * (D - G + Me.Width + 6) + G + D - Me.Width - 6) / 2 + 3
Me.Top = (Y * (B - H + Me.Height + 6) + H + B - Me.Height - 6) / 2 + 3
End Sub