7,785
社区成员




Private Sub Form_Resize() '注:子窗体的事件,并不是MDI主窗体的
Move 0, 0, Width, Height
End Sub
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Sub Form_Resize() '注:子窗体的事件,并不是MDI主窗体的
Dim RcWithClient As RECT
Dim hWndWithClient As Long
hWndWithClient = FindWindowEx(主窗体句柄, 0, "MDIClient", vbNullString)
If hWndWithClient Then
Call GetClientRect(hWndWithClient, RcWithClient)
'使子窗体在客户区里居中显示
Move ((RcWithClient.Right - RcWithClient.Left) / 15 - Width) / 2, _
((RcWithClient.Bottom - RcWithClient.Top) / 15 - Height) / 2, _
Width, Height
End If
End Sub
Private Sub Timer1_Timer()
Dim frm As Form
For Each frm In Forms
If frm.Name <> "MDI主窗体名称" Then
'这里写代码~~~~~~
'不过你可以判断一下子窗体的Left值和Top值,如果与你期望值相同的话就可以不用移动了
End If
Next frm
End Sub