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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
| Option Explicit
Private Type Ecran
WState As Long
ht As Double
lt As Double
tp As Double
Wh As Double
End Type
Enum ScreenID
ExcelDim = 1
ExcelClientDim = 2
UserFormDim = 3
End Enum
Dim l#, t#, h#, w#
Dim screenRef(2) As Ecran, screenCur(1) As Ecran
Private Sub CommandButton1_Click()
Me.Hide
End Sub
Private Sub FenetreState()
If OptEtendue.Value Then
Me.Move 5, 5, screenCur(0).Wh - 20, screenCur(0).ht - 20
Else
Me.Move screenCur(1).lt, screenCur(1).tp, screenCur(1).Wh, screenCur(1).ht
End If
ScrollZoom.Value = 100
End Sub
Private Sub OptNormal_Click()
FenetreState
End Sub
Private Sub OptEtendue_Click()
FenetreState
End Sub
Private Sub ScrollZoom_Change()
Me.Zoom = ScrollZoom.Value
LabelZoom.Caption = "Zoom " & ScrollZoom.Value & "%"
End Sub
'Reglage_Vue :
' Adapte l 'UserForm sur les proportions d'ecran
Private Sub Reglage_Vue()
With Me
.Move Left + l, Top + t, screenCur(1).Wh - (Width / 100 * w), screenCur(1).ht - (Height / 100 * h)
.ScrollLeft = 0
.ScrollTop = 0
.ScrollHeight = screenRef(2).ht '+ 50
.ScrollWidth = screenRef(2).Wh '+ 30
.ScrollBars = fmScrollBarsBoth
.KeepScrollBarsVisible = fmScrollBarsNone
' .Scroll 5, 5
End With
UpdateScreenForm
End Sub
Private Sub UpdateScreenForm()
With screenCur(1)
.ht = Height
.lt = Left
.tp = Top
.Wh = Width
.WState = Me.StartUpPosition
End With
End Sub
'AppCur_Dim :
' Remplit la variable de type Ecran avec la valeur correspondante à l'écran de l'application
Private Sub AppCur_Dim(surf As Ecran, Optional Conteneur As Boolean = False)
Dim scrState&
With Application
'store prev reglages
scrState = .WindowState
.WindowState = xlMaximized
If Conteneur Then
surf.ht = .UsableHeight
surf.lt = .Left
surf.tp = .Top
surf.Wh = .UsableWidth
Else
surf.ht = .Height
surf.lt = .Left
surf.tp = .Top
surf.Wh = .Width
End If
'restore prev config
.WindowState = scrState
'
surf.WState = scrState
End With
End Sub
'StatedefaultDim :
' - screen : Argument remplit avec les données stockées dans le fichier
' - id : indique l'élément d'enumeration ScreenID
' Les données sont crées si elles n'éxistent pas, ou recrées si une incohérence avec le nombre de contrôles
Private Sub StatedefaultDim(screen As Ecran, id As ScreenID)
Dim r As Range, n
On Error Resume Next
Set r = Range("Default")
If Err Then
Err.Clear
Set r = Sheets("Custom").Range("A1")
If Err Then
With Sheets.Add
.Name = "Custom"
Set r = .Range("A1:E1")
End With
End If
Sheets("Custom").Names.Add "Default", Sheets("Custom").Range("A1:E1")
End If
If r.Rows.CurrentRegion.Rows.Count < Controls.Count + 4 _
Or r.Rows.CurrentRegion.Rows.Count > Controls.Count + 4 Then
Dim cnt As Control
r.Worksheet.Cells.Clear
n = Application.WindowState
Application.WindowState = xlMaximized
With r
.Range("A1:E1") = Array("Ecran", "Left", "Top", "Width", "Height", "Parent")
'
.Cells(2, 1) = Application.Name
.Cells(2, 2) = Application.Left
.Cells(2, 3) = Application.Top
.Cells(2, 4) = Application.Width
.Cells(2, 5) = Application.Height
.Cells(2, 7) = Application.WindowState
'
.Cells(3, 1) = Application.Windows(1).Caption
.Cells(3, 2) = Application.Windows(1).Left
.Cells(3, 3) = Application.Windows(1).Top
.Cells(3, 4) = Application.Windows(1).Width
.Cells(3, 5) = Application.Windows(1).Height
.Cells(3, 7) = Application.WindowState
'
.Cells(4, 1) = Me.Name
.Cells(4, 2) = Left
.Cells(4, 3) = Top
.Cells(4, 4) = Width
.Cells(4, 5) = Height
.Cells(4, 7) = Me.StartUpPosition
End With
Application.WindowState = n
n = 4
For Each cnt In Controls
n = n + 1
With r
.Cells(n, 1) = cnt.Name
.Cells(n, 2) = cnt.Left
.Cells(n, 3) = cnt.Top
.Cells(n, 4) = cnt.Width
.Cells(n, 5) = cnt.Height
.Cells(n, 6) = cnt.Parent.Name
.Cells(n, 7) = TypeName(cnt)
End With
Next
End If
id = id + 1
With screen
.ht = r(id, 5)
.lt = r(id, 2)
.tp = r(id, 3)
.Wh = r(id, 4)
.WState = r(id, 6)
End With
End Sub
Private Sub UserForm_Activate()
UpdateScreenForm
End Sub
Private Sub UserForm_Initialize()
'
'Dim spc_Height#, spc_Width#
OptNormal.Caption = "Affichage normal"
OptNormal.AutoSize = True
'OptNormal.Value = True
OptEtendue.Caption = "Affichage étendu"
OptEtendue.AutoSize = True
CheckResizeWithZoom.Caption = "Ajuster Fenêtre avec le Zoom"
CheckResizeWithZoom.AutoSize = True
LabelZoom.Caption = "Zomm : 100%"
ScrollZoom.Min = 50
ScrollZoom.Max = 200
ScrollZoom.Value = 100
StatedefaultDim screenRef(0), ExcelDim
StatedefaultDim screenRef(1), ExcelClientDim
StatedefaultDim screenRef(2), UserFormDim
AppCur_Dim screenCur(0)
l = (screenCur(0).lt - screenRef(0).lt)
t = (screenCur(0).tp - screenRef(0).tp)
h = 100 - ((screenCur(0).ht / screenRef(0).ht) * 100)
w = 100 - ((screenCur(0).Wh / screenRef(0).Wh) * 100)
UpdateScreenForm
Reglage_Vue
End Sub
Private Sub UserForm_Zoom(Percent As Integer)
Static p&
Dim wt&, ht&, i&
Dim spc_Height#, spc_Width#
Dim cnt As Control
If CheckResizeWithZoom Then
wt = (Width * ((Percent - 100) - p) / 100)
ht = (Height * ((Percent - 100) - p) / 100)
Move Left, Top, Width + wt, Height + ht
ScrollHeight = screenRef(2).ht + (10 * Percent / ht)
ScrollWidth = screenRef(2).Wh + (10 * Percent / wt)
For Each cnt In Controls
wt = (cnt.Width * ((Percent - 100) - p) / 100)
ht = (cnt.Height * ((Percent - 100) - p) / 100)
cnt.Move cnt.Left + wt, cnt.Top + ht, cnt.Width + wt, cnt.Height + ht
Next
UpdateScreenForm
End If
p = p + ((Percent - 100) - p)
End Sub |
Partager