十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
直接添加一个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
要确立父子窗体,那子窗体必须继承父窗体。实例化子窗体对象调用Show()方法。
希望采纳
既然子窗体都有同名函数,就应该对子窗体进行一层封装,子类实现不同方法
Public MustInherit Class AbstractChild
Public MustOverride Sub Method1()
End Class
Public Class ChildClass1
Inherits AbstractChild
Public Overrides Sub Method1()
MessageBox.Show("class1")
End Sub
End Class
Public Class ChildClass2
Inherits AbstractChild
Public Overrides Sub Method1()
MessageBox.Show("class2")
End Sub
End Class
Public Class ChildClass3
Inherits AbstractChild
Public Overrides Sub Method1()
MessageBox.Show("class3")
End Sub
End Class
Dim child1 As New ChildClass1()
Dim child2 As New ChildClass2()
Dim child3 As New ChildClass3()
child1.Method1()
child2.Method1()
child3.Method1()
sub main()dim f1 as new form,f2 as new formf2.toplevel=falsef2.parent=f1f1.showf2.showapplication.run(f1)end sub