Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each MyMenu In Me.MenuStrip1.Items GetChildMenu(MyMenu) Next End Sub
Private Sub GetChildMenu(ByVal TheMenu As ToolStripMenuItem) If TheMenu.HasDropDownItems Then For Each m As ToolStripMenuItem In TheMenu.DropDownItems GetChildMenu(m) Next Else MsgBox(TheMenu.Text) '楼主分配权限的代码可以写在这里 End If End Sub
Private Sub GetChildMenu(ByVal TheMenu As ToolStripMenuItem) If TheMenu.HasDropDownItems Then For Each m In TheMenu.DropDownItems '注意这里的修改 If m.GetType.Name <> "ToolStripSeparator" Then GetChildMenu(m) '注意这里的判断 Next Else MsgBox(TheMenu.Text) '楼主分配权限的代码可以写在这里 End If End Sub
Public Function getmenu(ByVal dc As ToolStripMenuItem) As Integer
Dim sqlstr As String = ""
Dim objConnection As New SqlConnection(sqlstr)
Dim sql As String = ""
' 打开连接SqlConnection
Try
If dc.HasDropDownItems Then
For Each m In dc.DropDownItems
If m.GetType.Name <> "ToolStripSeparator" Then
getmenu(m)
End If
Next
Else
qxi = qxi + 1
End If
'开始保存菜单到SQL
sqlstr = getsqlstr()
' 创建数据库
objConnection = New SqlConnection(sqlstr)
If objConnection.State <> ConnectionState.Open Then
objConnection.Open()
End If
sql = "Insert into mymenu(id,菜单名,变量名) values(" + Str(qxi) + ",'" + Trim(dc.Text) + "','" + Trim(dc.Name) + "')" + vbCrLf
Dim cmd As SqlCommand = New SqlCommand(sql, objConnection)
Try
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
objConnection.Close()
objConnection.Dispose()
objConnection = Nothing
Catch ex As Exception
End Try
Return 0
End Function