21/01/2025 - luigice ha scritto:
Dall'attivazione di un interruttore si va ad una routine evento che abilita il menu in discesa degli altri interruttori che non erano visibili.
Ossia con = Forms![maschera iniziale]!Interruttore29.Visible = True
Ciao, in effetti hai un effetto Flickering per quanto spiegato da @Alex.
Una domanda se posso... perchè hai usato tutti questi "Interruttori" ? quale layout vuoi realizzare ? (solo per curiosità)
Cmq per darti un esempio io farei una cosa di questo tipo...per esempio utilizzando tre Interruttori inseriti in un gruppo e associando ad ogni interruttore una ListBox (casella di riepilogo) che si aprono al passaggio del mouse sotto ad ogni Interruttore.... sarebbe un poco più semplice e riflette un pò anche gli standard...
Solo per darti un idea, ma esistono tanti altri metodi:

e le quattro righe di codice saranno per esempio:
Option Compare Database
Option Explicit
' set variables global
Private CurrentListBox As ListBox
' FORM LOAD
Private Sub Form_Load()
' initialize menu
MyResetMenu
End Sub
' LISTBOX MENU 1
Private Sub Inter01_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetListBox 1, Me.List01
End Sub
' LISTBOX MENU 2
Private Sub Inter02_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetListBox 2, Me.List02
End Sub
' LISTBOX MENU 3
Private Sub Inter03_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetListBox 3, Me.List03
End Sub
' SET LISTBOX MENU
Private Sub SetListBox(IntInter As Integer, SelectListBox As ListBox)
' check current listbox to avoid flicker
If Not CurrentListBox Is Nothing Then If CurrentListBox.Name = SelectListBox.Name Then Exit Sub
' set focus
Me.GruppoMain.SetFocus
' set switch
Me.GruppoMain.Value = IntInter
' chek current listbox
If Not CurrentListBox Is Nothing Then
' hide current listbox
If CurrentListBox.Name <> SelectListBox.Name Then CurrentListBox.Visible = False
End If
' open listbox selected
SelectListBox.Visible = True
' save current listbox
Set CurrentListBox = SelectListBox
End Sub
' RESET MENU
Private Sub MyResetMenu()
' initialize listbox
Me.List01.Value = Null
Me.List02.Value = Null
Me.List03.Value = Null
' set focus
Me.GruppoMain.SetFocus
' hide listbox
Me.List01.Visible = False
Me.List02.Visible = False
Me.List03.Visible = False
Set CurrentListBox = Nothing
End Sub
' RESET MENU
Private Sub Corpo_Click()
' initialize menu
MyResetMenu
End Sub
La stessa logica potresti realizzarla anche solo con gli "Interruttori" ... (personalmente non piace molto, però vedi te...puoi prendere qualche spunto, è da moltissimo che non lavoro con il vba) ;-)
P.S. (edit)
Dimenticavo di segnalarti come evitare lo sfarfallio... in questo esempio viene eseguita la routine solo se effettivamente viene passato il mouse su di un nuovo Interruttore. Vedere le righe di codice e la spiegazione che ti ha dato @Alex:
' SET LISTBOX MENU
Private Sub SetListBox(IntInter As Integer, SelectListBox As ListBox)
' check current listbox to avoid flicker
If Not CurrentListBox Is Nothing Then If CurrentListBox.Name = SelectListBox.Name Then Exit Sub
...
....
......
Quindi se ti trovi ancora sullo stesso Interruttore si esce subito dalla Sub ( Then Exit Sub) e in questo modo si evita di ridisegnare ed impostare nuovamente i vari controlli.