'userform redimentionable avec les controls redimentionnables
'Createur Patricktoulon
'Date de Creation:26.06.2012
' Pour codesource
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Sub UserForm_Initialize()
'on determine le handle
handle= FindWindow(vbNullString, Me.Caption)
' on ajoute les deux boutons manquants et l'élasticité a la caption de l'userform
SetWindowLong handle, -16, GetWindowLong(handle, -16) Or &H70000
' affiche directement le userform en plein ecran et donne le focus a l'userform ( en avant de toute les autres)
ShowWindow handle,3
For Each ctrl In Me.Controls
' On se sert du tag pour memoriser les dimension des controls separé par un double point
ctrl.Tag = Me.Height / ctrl.Height & ":" & Me.Width / ctrl.Width & ":" & Me.Width / ctrl.Left & ":" & Me.Height / ctrl.Top
If TypeName(ctrl) = "CommandButton" Or TypeName(ctrl) = "Label" Or TypeName(ctrl) = "TextBox" Then ctrl.Tag = ctrl.Tag & ":" & Me.Width / ctrl.Font.Size
Next
End Sub
Private Sub UserForm_Resize()
For Each ctrl In Me.Controls
'le tag comporte les diviseurs de l'userform pour obtenir les dimension du control
ctrl.Move Me.Width / Split(ctrl.Tag, ":")(2), Me.Height / Split(ctrl.Tag, ":")(3), Me.Width / Split(ctrl.Tag, ":")(1), Me.Height / Split(ctrl.Tag, ":")(0)
If TypeName(ctrl) = "CommandButton" Or TypeName(ctrl) = "Label" Or TypeName(ctrl) = "TextBox" Then ctrl.Font.Size = Me.Width / Split(ctrl.Tag, ":")(4)
Me.Repaint
Next
End Sub