动态增添和移除菜单VB源码程序,程序员在编程的过程中可以参考学习使用,希望对IT程序员有用,此源码程序简单易懂、方便阅读,有很好的学习价值!
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1440
ClientLeft = 2280
ClientTop = 3060
ClientWidth = 3300
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 1440
ScaleWidth = 3300
Begin VB.CommandButton CmdRemove
Cancel = -1 'True
Caption = "删除"
Height = 495
Left = 1800
TabIndex = 3
Top = 720
Width = 1215
End
Begin VB.CommandButton CmdAdd
Caption = "增加"
Default = -1 'True
Height = 495
Left = 240
TabIndex = 2
Top = 720
Width = 1215
End
Begin VB.TextBox CaptionText
Height = 285
Left = 1080
TabIndex = 1
Top = 240
Width = 1935
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "菜单名称"
Height = 180
Left = 240
TabIndex = 0
Top = 240
Width = 720
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuFileList
Caption = "新加菜单"
Index = 0
Visible = 0 'False
End
Begin VB.Menu mnuFileSep
Caption = "-"
Visible = 0 'False
End
Begin VB.Menu mnuFileExit
Caption = "退出(&E)"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private max_index As Integer
Private Sub CmdAdd_Click()
' Load the new menu item.
max_index = max_index + 1
Load mnuFileList(max_index)
mnuFileList(max_index).Caption = CaptionText.Text
mnuFileList(max_index).Visible = True
CaptionText.Text = ""
' Make the separator visible.
mnuFileSep.Visible = True
End Sub
Private Sub CmdRemove_Click()
Dim txt As String
Dim ctl As Menu
' Find the menu item with this caption.
txt = CaptionText.Text
CaptionText.Text = ""
For Each ctl In mnuFileList
If ctl.Caption = txt Then Unload ctl
Next ctl
' Make the separator visible.
If mnuFileList.Count < 2 Then _
mnuFileSep.Visible = False
End Sub
Private Sub Form_Load()
End Sub
Private Sub mnuFileExit_Click()
Unload Me
End Sub
Private Sub mnuFileList_Click(Index As Integer)
MsgBox "Selected item" & Str$(Index)
End Sub