既然子窗体都有同名函数,就应该对子窗体进行一层封装,子类实现不同方法
创新互联专注于任城企业网站建设,响应式网站,商城网站开发。任城网站建设公司,为任城等地区提供建站服务。全流程定制网站制作,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
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()
直接添加一个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()方法。
希望采纳
简单一点的方式是,在MDI主窗体内添加一个picturebox控件,然后在这个picturebox中添加一个image控件。
Picture1的属性:
1.Align=top
2.Appearance=flat
3.BordeStyle=None
4.TabStop=false
Image1的属性:
1.Stretch=true
在MDI窗体的resize事件中添加如下代码:
Private Sub MDIForm_Resize()
Me.Picture1.Height = Me.Height
End Sub
在Picture1控件的resize事件中添加如下代码:
Private Sub Picture1_Resize()
Me.Image1.Move 0, 0, Me.Picture1.Width, Me.Picture1.Height
End Sub