On Sun, 30 Mar 2003 10:54:54 GMT, "Calan"
Quote:
>I'm exploring ways of optimizing my menus, toolbars, and command buttons. I
>have several menu items (and their corresponding toolbar and command
>buttons) that get enabled or disabled at various times based on several
>program conditions and user actions.
<snip>
> It would be nice to just enable/disable a menu item, and have this
>fire an event (a menu enabled event?) that could contain the code to control
>the related buttons.
>Any ideas?
You could do the following
A Form and a Class follow :-
Option Explicit
Dim WithEvents MnuMgr As cMnuMgr
====== FORM1.FRM ========
Option Explicit
Dim WithEvents MnuMgr As cMnuMgr
Private Sub Form_Load()
Set MnuMgr = New cMnuMgr
End Sub
Private Sub Command1_Click()
MnuMgr.SetEnabled(mnuFile) = False
End Sub
Private Sub MnuMgr_ChangeState(Mnu As Menu)
Dim B As Boolean
Me.Print Mnu.Name
B = Mnu.Enabled
Select Case True
Case (Mnu Is mnuFile) = True
Command1.Enabled = B
End Select
End Sub
======= cMnuMgr.CLS ======
Option Explicit
Public Event ChangeState(Mnu As Menu)
Public Property Let SetEnabled(Mnu As Menu, Value As Boolean)
Mnu.Enabled = Value
RaiseEvent ChangeState(Mnu)
End Property
===========================
The idea is that one sets the enabled property using :-
MnuMgr.SetEnabled( mnuFile ) = False
Realistically it is not that much better than calling the routine
directly rather than the 'indirection' of using the Class
ie: using a Property within the Form
or putting the whole thing somewhere else to isolate it
However the Select Case routine would probably simplify things for you
- as would the use of just one Flag ( B As Boolean )
I think I would just go for a simple routine, with the Select Case
stuff inside it.
Maybe it will give you some ideas ...