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 Lft As Double, Rgt As Double, Top As Double, Bot As Double, U As Object, _
UInsWidth As Single, UInsHeight As Single, K As Double, Zom As Double
If TypeOf Obj Is MSForms.Control Then
Lft = Obj.Left: Top = Obj.Top: Set U = Obj.Parent ' Normalement Page, Frame ou UserForm
Do: UInsWidth = U.InsideWidth: UInsHeight = U.InsideHeight ' Le Page en est pourvu, mais pas le Multipage.
If TypeOf U Is MSForms.Page Then Set U = U.Parent ' On prend le Multipage, car le Page n'a aucune propriété de Positionnement.
K = (U.Width - UInsWidth) / 2
Lft = Lft + U.Left + K: Top = Top + U.Top + U.Height - K - UInsHeight
If Not (TypeOf U Is MSForms.Frame Or TypeOf U Is MSForms.MultiPage) Then Exit Do
Set U = U.Parent: Loop
Rgt = Lft + Obj.Width: Bot = Top + Obj.Height
Else
Zom = ActiveWindow.Zoom / 100
K = GetDeviceCaps(GetDC(0), 88) / 72
Lft = ActiveWindow.PointsToScreenPixelsX(Obj.Left * K * Zom) / K
Rgt = ActiveWindow.PointsToScreenPixelsX((Obj.Left + Obj.Width) * K * Zom) / K
K = GetDeviceCaps(GetDC(0), 90) / 72
Top = ActiveWindow.PointsToScreenPixelsY(Obj.Top * K * Zom) / K
Bot = ActiveWindow.PointsToScreenPixelsY((Obj.Top + Obj.Height) * K * Zom) / K
End If
Me.Left = (X * (Rgt - Lft + Me.Width + 6) + Lft + Rgt - Me.Width - 6) / 2 + 3
Me.Top = (Y * (Bot - Top + Me.Height + 6) + Top + Bot - Me.Height - 6) / 2 + 3
End Sub