关于树形菜单,如何简化菜单代码,在数据表中进行菜单设置,点击节点打开相应的窗体?
Dim frm As FormFor Each frm In Forms
If frm.Name = "Form1" Then
frm.show
End If
Next
但上面的代码没法实现,“For Each frm In Forms”这句代码查资料是说只能在加载的窗体中查找,请问版主怎么实现?
Private Sub Timer1_Timer() Static AFhWnd As Long '上一次扫描时活动窗体 hWnd Static FrmCount As Long '上一次扫描时总窗体数 Dim frm As Form, i As Long If Forms.Count > 1 Then '如果当前窗体数量>1 '如果保存的活动窗体没有发生变化 并且总窗体数也没变化时不处理 If Me.ActiveForm.hWnd = AFhWnd And FrmCount = Forms.Count Then Exit Sub Else Exit Sub End If FrmCount = Forms.Count Debug.Print AFhWnd, FrmCount '清list2中的选择 For i = 0 To List2.ListCount - 1 List2.Selected(i) = False Next i '遍类所有的窗体 For Each frm In Forms If Not frm Is Me Then '不是mdi窗体,本过程是写在 MDI窗体代码中 For i = 0 To List2.ListCount - 1 If List2.List(i) = frm.hWnd Then List2.Selected(i) = True Exit For End If Next i '未找到,则添加 If i > List2.ListCount - 1 Then List1.AddItem frm.Caption List2.AddItem frm.hWnd List2.Selected(i) = True End If End If If frm Is Me.ActiveForm Then GotFocusYN = True List1.ListIndex = i AFhWnd = frm.hWnd GotFocusYN = False End If Next '清已经关闭的窗体记录 For i = List2.ListCount - 1 To 0 Step -1 If Not List2.Selected(i) Then List1.RemoveItem i List2.RemoveItem i End If Next i End Sub