CodeItBetter Programming Another VB Programming Blog

How to enable/disable submenus of Edit menu (Copy, Cut, Clear, Undo, and so on) based on text selection

Posted on July 22, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'Forms - How to enable/disable submenus of Edit menu (Copy, Cut, Clear, Undo, and so on) based on text selection
'The state of most of the commands in a typical Edit menu (Copy, Cut, Clear,
'Undo, and so on) depends on whether any text is currently selected in the active
'control. In this case, changing the menu state any time a condition changes
'(because the user selects or deselects text in the active control, for example)
'is a waste of time, and it also requires a lot of code. Therefore, it's
'preferable to set the state of those menu commands in the parent menu's Click
'event just before displaying the menu:

Private Sub mnuEdit_Click()
    ' The user has clicked on the Edit menu,
    ' but the menu hasn't dropped down yet.
    On Error Resume Next
    ' Error handling is necessary because we don't know if
    ' the Active control actually supports these properties.
    mnuEditCopy.Enabled = (ActiveControl.SelText <> "")
    mnuEditCut.Enabled = (ActiveControl.SelText <> "")
    mnuEditClear.Enabled = (ActiveControl.SelText <> "")
End Sub
Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.