如何在Access的窗体中添加子窗体

如何在Access的窗体中添加子窗体,第1张

窗体实际上也是窗体,只不过它是被嵌入在一个窗体中而已,用户可以轻松地在窗体中添加子窗体。其 *** 作步骤如下:STEP1:在窗体“设计视图”中打开要向其中添加子窗体的窗体,单击“控件向导”按钮。STEP2:在“工具箱”工具栏中单击“子窗体/子报表”按钮。STEP3:在窗体中按住鼠标左键拖动,以确定放置子窗体的位置及窗体大小,释放鼠标后,一个子窗体就创建好了,可用此方法创建多个子窗体。

直接添加一个MID父窗体或在已有窗体的属性中找到IsMDIContainer属性,然后设置为True,然后创建第二个窗体 ,需要加载子窗体的时候:

Dim NewMDIChild As New Form2

NewMDIChild.MdiParent = Me

NewMDIChild.Show()

Public Shared Sub CheckMDIChildForm(ByVal MDIForm As Windows.Forms.Form, ByVal MDIChildForm As Windows.Forms.Form, ByVal MDIChildFormName As String)

        If MDIForm.MdiChildren.Length < 1 Then

            '如果没有任何一个MDI子窗体,则创该MDI子窗体的窗体实例

            Dim MDIChildFrm As Windows.Forms.Form = MDIChildForm ' 定义MDI子窗体

            MDIChildFrm.MdiParent = MDIForm '指定父窗体

            MDIChildFrm.Show() '打开窗体

            Exit Sub

        Else

            Dim x As Integer

            Dim frmyn As Boolean

            For x = 0 To (MDIForm.MdiChildren.Length) - 1

                Dim tempChild As Windows.Forms.Form = CType(MDIForm.MdiChildren(x), Windows.Forms.Form)

                If tempChild.Name = MDIChildFormName Then

                    '检测到有该MDI子窗体,设为激活 并退出循环

                    frmyn = True

                    tempChild.BringToFront()

                    Exit For

                Else

                    frmyn = False

                End If

            Next

            If Not frmyn Then

                '在打开的窗体中没检测到则新建

                Dim MDIChildFrm As Windows.Forms.Form = MDIChildForm ' 定义MDI子窗体

                MDIChildFrm.MdiParent = MDIForm '指定父窗体

                MDIChildFrm.Show() '打开窗体

            End If

        End If

    End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11757012.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存