VB中如何制作网页收藏夹,详细请看介绍
- 提问者网友:一抹荒凉废墟
- 2021-04-25 12:37
- 五星知识达人网友:躲不过心动
- 2021-04-25 13:19
我估计你想动态增加菜单
Private Sub Form_Load()
mnuDynaDel.Enabled = False
mnuDynaDelLast.Enabled = False
End Sub
Private Sub mnuDynaAdd_Click()
''增加一个指定标题的菜单
Dim str
str = InputBox("输入所要增加的菜单项的标题", "菜单标题", "MenuName")
Dim i As Integer
i = mnuDynaArray.UBound
Load mnuDynaArray(i + 1)
If str = "" Then str = "新增菜单项,索引号为" & mnuDynaArray(i + 1).Index
mnuDynaArray(i + 1).Caption = str
mnuDynaArray(i + 1).Visible = True
mnuDynaArray(0).Visible = True
mnuDynaDel.Enabled = True
mnuDynaDelLast.Enabled = True
End Sub
Private Sub mnuDynaDel_Click()
''删除一个指定标题的菜单
''取得所要删除的菜单标题
Dim str
str = InputBox("输入所要删除的菜单项的标题")
''寻找所要删除的菜单项
Dim item, curItem
For Each item In mnuDynaArray
If item.Caption = str Then
curItem = item
Exit For
End If
Next item
If Not IsEmpty(curItem) Then
''如果找到了所要删除的菜单项,则删掉它
Unload mnuDynaArray(curItem)
If mnuDynaArray.Count <= 1 Then
mnuDynaDel.Enabled = False
mnuDynaDelLast.Enabled = False
mnuDynaArray(0).Visible = False
End If
Else
''如果没有找到所要删除的菜单项,则提示报错
MsgBox "没有找到您所要删除的菜单项!", vbCritical
End If
End Sub
Private Sub mnuDynaDelLast_Click()
''删除末尾的一个菜单项
Dim i As Integer
i = mnuDynaArray.UBound
Unload mnuDynaArray(i)
i = mnuDynaArray.UBound
If i = 0 Then
mnuDynaDel.Enabled = False
mnuDynaDelLast.Enabled = False
mnuDynaArray(0).Visible = False
End If
End Sub
Private Sub mnuDynaArray_Click(Index As Integer)
''菜单项的Click响应事件
MsgBox "您所点击的菜单项的名称为:" & mnuDynaArray(Index).Caption
''对所点击的菜单项设置复选标记
''取消其他菜单项的复选标记
Dim item
For Each item In mnuDynaArray
item.Checked = False
Next item
mnuDynaArray(Index).Checked = True
End Sub
Private Sub mnuDynaExit_Click()
Unload Me
End Sub