Private Sub UserForm_Activate() 'PatrickToulon code proposé dans initialize
'Plein Ecran UserForm
Dim ctl As Control, ratioW#, ratioH#, wstate&, i&, ClW
With Application: wstate = .WindowState: .WindowState = xlMaximized:
ratioW = Application.Width / Me.Width
ratioH = Application.Height / Me.Height
.WindowState = wstate
End With
' pour l'exemple j'ajoute une listbox avec 2 colonnes
' With ListBox1: .List = [A1:B5].Value: .ColumnCount = 2: .ColumnWidths = "30;60": End With
DoEvents
With Me
.StartUpPosition = 0: .Left = 0: .Top = 0
.Width = (.Width * ratioW) - (.Width - .InsideWidth)
.Height = (.Height * ratioH) - (.Height - .InsideHeight) + (.Width - .InsideWidth)
End With
For Each ctl In Me.Controls
ctl.Move ctl.Left * ratioW, ctl.Top * ratioH, ctl.Width * ratioW, ctl.Height * ratioH
Select Case TypeName(ctl)
Case "TextBox", "Label", "Frame", "CommandButton", "MultiPage", "ListBox", "ComboBox", "CheckBox", "OptionButton"
ctl.Font.Size = ctl.Font.Size * Application.Min(ratioH, ratioW)
End Select
If TypeOf ctl Is msforms.ListBox Then
If ctl.ColumnWidths = "" Then ClW = Split(Trim(Application.Rept(70 & " ", ctl.ColumnCount)), " ") Else ClW = Split(Replace(ctl.ColumnWidths, " pt", ""), ";")
For i = 0 To UBound(ClW): ClW(i) = Val(ClW(i)) * ratioW: Next
ctl.ColumnWidths = Join(ClW, ";")
End If
Next
End Sub