'*****************************************************************************************************
' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _.
' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| //
' //___// //__\ // //__// // // //__// // // // // // // // // // | //
' // // \\ // // \\ // // // \\ // // // // // // // // // | //
'// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |//
'****************************************************************************************************
' Collection Module classe by patricktoulon
'Classe de gestion de pseudo events Enter et Exit pour les textbox
'version 4.0
'date version:20/04/2024
''**************************************************************************************************
Option Explicit
Public WithEvents TxtBox As MSForms.TextBox
Public WithEvents bouton As MSForms.CommandButton
Public WithEvents opt As MSForms.OptionButton
Public WithEvents Check As MSForms.CheckBox
Public WithEvents toggle As MSForms.ToggleButton
Public WithEvents LstBox As MSForms.ListBox
Public WithEvents Combo As MSForms.ComboBox
Public WithEvents Image As MSForms.Image
Public WithEvents spin As MSForms.SpinButton
Public WithEvents multi As MSForms.MultiPage
Public WithEvents fram As MSForms.frame
Public WithEvents forme As UserForm
Public WithEvents lsView As ListView
Public memoire As TxtBoxEnterExit
Public usf As Object
Public oldcontrol 'As Control
Public AllClass As New Collection
Public nam As String
Function init(usf)
Dim cls() As New TxtBoxEnterExit
Dim CtrL, A&, first
Me.nam = "mère"
For Each CtrL In usf.Controls
If TypeOf CtrL Is TextBox Or TypeName(CtrL) = "TextBox" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).TxtBox = CtrL: CtrL.Value = CtrL.Name
If TypeOf CtrL Is OptionButton Or TypeName(CtrL) = "OptionButton" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).opt = CtrL
If TypeOf CtrL Is CommandButton Or TypeName(CtrL) = "CommandButton" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).bouton = CtrL
If TypeOf CtrL Is CheckBox Or TypeName(CtrL) = "CheckBox" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).Check = CtrL
If TypeOf CtrL Is ToggleButton Or TypeName(CtrL) = "ToggleButton" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).toggle = CtrL
If TypeOf CtrL Is ListBox Or TypeName(CtrL) = "ListBox" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).LstBox = CtrL
If TypeOf CtrL Is ComboBox Or TypeName(CtrL) = "Combobox" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).Combo = CtrL
If TypeOf CtrL Is Image Or TypeName(CtrL) = "Image" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).Image = CtrL
If TypeOf CtrL Is frame Or TypeName(CtrL) = "Frame" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).fram = CtrL
If TypeOf CtrL Is SpinButton Or TypeName(CtrL) = "SpinButton" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).spin = CtrL
If TypeOf CtrL Is MultiPage Or TypeName(CtrL) = "multipage" Then A = A + 1: ReDim Preserve cls(1 To A): Set cls(A).multi = CtrL
cls(A).nam = CtrL.Name
Set cls(A).forme = usf
Set cls(A).memoire = Me
If A = 1 Then
Set first = usf.Controls(0)
If TypeName(first) = "Frame" Then Set first = first.Controls(0)
If TypeName(first) = "MultiPage" Then Set first = first.Pages(first.Value).Controls(0)
Set cls(A).memoire.oldcontrol = first
End If
AllClass.Add cls(A)
Next
Erase cls
End Function
Private Sub Class_Terminate()
MsgBox "classe " & Me.nam & " terminée"
End Sub
Private Sub resultat()
Dim ControlIn, ControlOut
Set ControlIn = forme.ActiveControl
Set ControlOut = memoire.oldcontrol
'Déviation d'affiliation pour les controls eventuellement placés dans une frame ou multipage
If TypeName(ControlIn) = "Frame" Then Set ControlIn = ControlIn.ActiveControl
If TypeName(ControlIn) = "MultiPage" Then Set ControlIn = ControlIn.Pages(ControlIn.Value).ActiveControl
'envoie aux pseudo events
If ControlIn.Name <> ControlOut.Name Then
If TypeName(ControlOut) = "TextBox" Then Control_Exit forme.Controls(ControlOut.Name)
If TypeName(ControlIn) = "TextBox" Then Control_Enter forme.Controls(ControlIn.Name)
End If
'on met a jour oldcontrol avec le control actif pour le prochain tour
Set memoire.oldcontrol = ControlIn
End Sub
Private Sub Class_Initialize()
End Sub
'les event key_down
'Private Sub TxtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = TxtBox: End Select: End Sub
'Private Sub Opt_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = opt: End Select: End Sub
'Private Sub bouton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = bouton: End Select: End Sub
'Private Sub Check_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = Check: End Select: End Sub
'Private Sub Toggle_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = toggle: End Select: End Sub
'Private Sub LstBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = LstBox: End Select: End Sub
'Private Sub Combo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = Combo: End Select: End Sub
'Private Sub image_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): Select Case KeyCode: Case 9, 13: Set memoire.oldcontrol = Image: End Select: End Sub
'les events key_Up
Private Sub TxtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub opt_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub bouton_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub Combo_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub LstBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub image_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub toggle_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub Check_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub spin_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer): resultat: End Sub
Private Sub LsView_KeyUp(KeyCode As Integer, ByVal Shift As Integer): resultat: End Sub
'les events mouse_Down
Private Sub bouton_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub opt_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub TxtBox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub LstBox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub Combo_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub toggle_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub Check_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub image_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub Multi_MouseDown(ByVal Index As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub fram_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single): resultat: End Sub
Private Sub LsView_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS): resultat: End Sub
Private Sub Spin_SpinDown(): resultat: End Sub
Private Sub Spin_SpinUp(): resultat: End Sub
'les faux events Exit et Enter
Sub Control_Enter(ctrlY)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Enter : " & ctrlY.Name
End Sub
Sub Control_Exit(ctrlX)
Cells(Rows.Count, 1).End(xlUp).Offset(1) = " Exit : " & ctrlX.Name
End Sub