VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.Menu CtrlMenu 
      Caption         =   "菜单控制"
      Begin VB.Menu ShowHide 
         Caption         =   "显示/隐藏主菜单项"
      End
      Begin VB.Menu AddMenu 
         Caption         =   "增加菜单项"
      End
      Begin VB.Menu DelMenu 
         Caption         =   "删除菜单项"
         Enabled         =   0   'False
      End
   End
   Begin VB.Menu DynaMenu 
      Caption         =   "动态菜单"
      Visible         =   0   'False
      Begin VB.Menu DMenu 
         Caption         =   "菜单项 1"
         Index           =   1
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub AddMenu_Click()
    Dim Dm As Integer
    Dm = DMenu.Count + 1        '计算索引值
    Load DMenu.Item(Dm)                '增加索引为Dm的新菜单项
    DMenu.Item(Dm).Caption = "菜单项" + Str(Dm) '为新菜单项设置标题
    DMenu.Item(Dm).Visible = True   '显示新增菜单项
    MsgBox "新增菜单项" + Str(DMenu.Count)
    DelMenu.Enabled = True          '使删除菜单可有用
End Sub

Private Sub DelMenu_Click()
    If DMenu.Count > 1 Then
        Unload DMenu.Item(DMenu.Count)  '删除菜单项
        If DMenu.Count = 1 Then
            DelMenu.Enabled = False     '使删除菜单不可用
        End If
    End If
End Sub

Private Sub Form_Load()

End Sub

Private Sub ShowHide_Click()
    If ShowHide.Checked = True Then
        ShowHide.Checked = False    '隐藏复选标记
        DynaMenu.Visible = False    '隐藏“动态菜单”项
    Else
        ShowHide.Checked = True     '显示复选标记
        DynaMenu.Visible = True     '显示“动态菜单”项
    End If
End Sub
