一次打开好几个子窗体
请问如何一次全部都把子窗体关掉另外如何取得特定的子窗体呢谢谢

解决方案 »

  1.   

    如果真有父子关系的话,关闭父窗口的时候,其子窗口自然会自己关闭!!!
    如果没有父子关系,可以用下列方法关闭所有窗口:Dim frm As Form
        
        For Each frm In Forms
            Unload frm
        Next
      

  2.   

    1.clsWindowsInfo.cls
    Option Explicit
    '用以主控存储窗体信息的类Private mfrmWindows As Form
    Private mlngWindowsMenuIndex As Long'窗体名称
    Public Property Get WindowsName() As String
        WindowsName = mfrmWindows.Name
    End Property'窗体标签
    Public Property Get WindowsCaption() As String
        WindowsCaption = mfrmWindows.Caption
    End Property'窗体句柄
    Public Property Get WindowshWnd() As String
        WindowshWnd = mfrmWindows.hwnd
    End Property'窗体对象
    Public Property Get WindowsForm() As Form
        Set WindowsForm = mfrmWindows
    End Property'窗体对象
    Public Property Set WindowsForm(frm As Form)
        Set mfrmWindows = frm
    End Property'窗体对应Menu的Index
    Public Property Get WindowsMenuIndex() As Long
        WindowsMenuIndex = mlngWindowsMenuIndex
    End Property'窗体对应Menu的Index
    Public Property Let WindowsMenuIndex(ByVal value As Long)
        mlngWindowsMenuIndex = value
    End Property2.clsMainControl.cls
    Option ExplicitPrivate mcolWindows As New Collection'窗体信息类集合
    Public Property Get WindowsCollection() As Collection
        Set WindowsCollection = mcolWindows
    End Property'窗体信息类
    Public Property Get WindowsInfo(ByVal strKey As String) As clsWindowsInfo
        Set WindowsInfo = mcolWindows.Item(strKey)
    End Property'子窗体个数
    Public Property Get WindowsCount() As Long
        WindowsCount = mcolWindows.Count
    End Property'加入主控
    Public Function Add(frm As Form) As clsWindowsInfo
    Dim clsWindows As New clsWindowsInfo
    Dim lngMenuCount As Long
        Set clsWindows.WindowsForm = frm
        mcolWindows.Add Item:=clsWindows, Key:=clsWindows.WindowshWnd
        If Not frmMain.ActiveForm Is Nothing Then
        End If
        Set Add = clsWindows
    End Function'移出主控
    Public Sub Remove(frm As Form)
    Dim lngIndex As Long
        For lngIndex = 1 To mcolWindows.Count
            If frm.hwnd = CLng(mcolWindows.Item(lngIndex).WindowshWnd) Then
                Unload frmMain.mnuWindowItem(mcolWindows.Item(lngIndex).WindowsMenuIndex)
                Exit For
            End If
        Next
        mcolWindows.Remove CStr(frm.hwnd)
    End Sub自己扩充吧
      

  3.   

    MDI窗口中,如果其他窗口的MDICHILD属性为TRUE则表明此窗口为MDI窗口的子窗口.
    Form1.Show , Form2 表明Form1是Form2的子窗口,在FORM2关闭时候,会自动的关闭FORM1
      

  4.   

    补充add函数代码
    '加入主控
    Public Function Add(frm As Form) As clsWindowsInfo
    Dim clsWindows As New clsWindowsInfo
    Dim lngMenuCount As Long
        Set clsWindows.WindowsForm = frm
        mcolWindows.Add Item:=clsWindows, Key:=clsWindows.WindowshWnd
        frmMain.mnuWindows.Visible = True
        If Not frmMain.ActiveForm Is Nothing Then
            Load frmMain.mnuWindowItem(mcolWindows.Count)
            frmMain.mnuWindowItem(mcolWindows.Count).Caption = clsWindows.WindowsCaption
            frmMain.mnuWindowItem(mcolWindows.Count).Tag = clsWindows.WindowshWnd
            frmMain.mnuWindowItem(0).Visible = False
            For lngMenuCount = 1 To mcolWindows.Count - 1
                frmMain.mnuWindowItem(lngMenuCount).Checked = False
            Next
            frmMain.mnuWindowItem(mcolWindows.Count).Visible = True
            frmMain.mnuWindowItem(mcolWindows.Count).Checked = True
            clsWindows.WindowsMenuIndex = mcolWindows.Count
        End If
        
        Set Add = clsWindows
    End Function
    frmmain是MDI窗体,frmmain.mnuwindowsitem是窗口菜单