大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
直接添加一个MID父窗体或在已有窗体的属性中找到IsMDIContainer属性,然后设置为True,然后创建第二个窗体 ,需要加载子窗体的时候:
创新互联公司公司2013年成立,先为共和等服务建站,共和等地企业,进行企业商务咨询服务。为共和企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
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
在工程管理窗口中单击右键,选择添加MDI窗体。
再添加两个普通窗体,更改属性MDIChild=true即可。
DllImport("user32.dll", ExactSpelling:=True) _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal uFlags As UInteger) As Integer
End Function
Private Const GWL_STYLE As Integer = -16
Private Const GWL_EXSTYLE As Integer = -20
Private Const WS_BORDER As Integer = H800000
Private Const WS_EX_CLIENTEDGE As Integer = H200
Private Const SWP_NOSIZE As UInteger = H1
Private Const SWP_NOMOVE As UInteger = H2
Private Const SWP_NOZORDER As UInteger = H4
Private Const SWP_NOREDRAW As UInteger = H8
Private Const SWP_NOACTIVATE As UInteger = H10
Private Const SWP_FRAMECHANGED As UInteger = H20
Private Const SWP_SHOWWINDOW As UInteger = H40
Private Const SWP_HIDEWINDOW As UInteger = H80
Private Const SWP_NOCOPYBITS As UInteger = H100
Private Const SWP_NOOWNERZORDER As UInteger = H200
Private Const SWP_NOSENDCHANGING As UInteger = H400
Public Sub ChangeMdiClientBorderStyle(ByVal Value As System.Windows.Forms.BorderStyle, ByVal Handle As IntPtr)
Dim style As Integer = GetWindowLong(Handle, GWL_STYLE)
Dim exStyle As Integer = GetWindowLong(Handle, GWL_EXSTYLE)
' Add or remove style flags as necessary.
Select Case Value
Case BorderStyle.Fixed3D
exStyle = exStyle Or WS_EX_CLIENTEDGE
style = style And Not WS_BORDER
Exit Select
Case BorderStyle.FixedSingle
exStyle = exStyle And Not WS_EX_CLIENTEDGE
style = style Or WS_BORDER
Exit Select
Case BorderStyle.None
style = style And Not WS_BORDER
exStyle = exStyle And Not WS_EX_CLIENTEDGE
Exit Select
End Select
' Set the styles using Win32 calls
SetWindowLong(Handle, GWL_STYLE, style)
SetWindowLong(Handle, GWL_EXSTYLE, exStyle)
' Update the non-client area.
SetWindowPos(Handle, IntPtr.Zero, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOOWNERZORDER Or SWP_FRAMECHANGED)
End Sub
''' summary
''' 获取MDIClient句柄
''' /summary
''' returns/returns
''' remarks/remarks
Private Function getMdiClientHandle() As IntPtr
Dim Obj As MdiClient = Nothing
Dim t As Type
For Each Item As Control In Me.Controls
t = Item.[GetType]()
If t.Name = "MdiClient" Then
Obj = DirectCast(Item, MdiClient)
Exit For
End If
Next
If Obj IsNot Nothing Then
Return Obj.Handle
Else
Return IntPtr.Zero
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Me.IsMdiContainer Then
ChangeMdiClientBorderStyle(BorderStyle.None, getMdiClientHandle)
End If
End Sub