1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| '*****************************************************************************
'**********************************************************************************************************************
'* CREATEUR :Patrick toulon Alias chamalin2@Hotmail.fr *
'* DATE :23/09/2010 *
'* UTILISATION D'UNE SEULE API LE "USER32.DLL" *
'* EXEMPLE DE USERFORM REDIMENTIONNABLE NOUVELLE VERSION *
'* LES CONTROLS SONT REDIMENTIONNES EN MEME TEMPS *
'* AINSI QUE LES FONT SIZE *
'* *
'* REVISION:12/07/2018 *
'* ajout support webbrowser *
'* simplification et intergation du code complet dans le Userform *
'* *
'*le font size est géré control par control ,il peuvent donc avoir un fontsize différent *
'* *
'**********************************************************************************************************************
Option Explicit
Private Declare Function FWA Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SWH Lib "User32" Alias "ShowWindow" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SWLA Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GWLA Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public old_largeur As Long, handle As Long, old_hauteur As Long, newhauteur As Single, newlargeur As Single
Dim Ctl As Object
Dim ctrl As Object
Private Sub UserForm_Activate()
trois_boutons Me
plein_ecran
With WebBrowser1
.Navigate "https://www.developpez.net/forums/d1873237/logiciels/microsoft-office/excel/macros-vba-excel/adapter-taille-d-webbrowser-fonction-taille-l-ecran/"
.Silent = True
End With
End Sub
Private Sub UserForm_Resize()
maForm_Resize Me
End Sub
Public Sub trois_boutons(uf As Object) 'on va ajouter les deux boutons manquants et l'élasticité a l'userform
'*******************************************************************
'*ici on memorise les dimention de depart de l'userform *
old_largeur = uf.InsideWidth: old_hauteur = uf.InsideHeight '*
'*******************************************************************
'*******************************************************************************************************************
For Each ctrl In uf.Controls '*
If TypeName(ctrl) <> "ScrollBar" And TypeName(ctrl) <> "Image" And TypeName(ctrl) <> "SpinButton" And _
TypeName(ctrl) <> "WebBrowser" Then ctrl.Tag = uf.InsideWidth / ctrl.Font.Size '*
Next '*
SWLA FWA(vbNullString, uf.Caption), -16, &H94CF0080
End Sub
Public Sub plein_ecran()
'1= mode normal
'3 =maximiser
'6 =minimiser
'le handle a été declaré en public au debut dans le activate de l'userform
SWH FWA(vbNullString, Me.Caption), 3
End Sub
Public Sub maForm_Resize(usf As Object)
newlargeur = usf.InsideWidth / old_largeur: newhauteur = usf.InsideHeight / old_hauteur
For Each Ctl In usf.Controls
Ctl.Move Ctl.Left * newlargeur, Ctl.Top * newhauteur, Ctl.Width * newlargeur, Ctl.Height * newhauteur
'tout les controls qui ont le multiplicateur enregistré dans leurs tags respectifs verront leur font size redimentionné en proportion
If Ctl.Tag <> "" Then Ctl.Font.Size = Round(usf.InsideWidth / Ctl.Tag, 0) - 1
Next
'ici on indique que l'ancienne largeur devient la nouvelle largeur et pareil pour la hauteur indispensable pour un futur redimentionnement
old_largeur = usf.InsideWidth: old_hauteur = usf.InsideHeight: usf.Repaint
End Sub |
Partager