Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Sub Form_Load() SetWindowPos hwnd, -1, 0, 0, 0, 0, 3 End Sub
在窗体2里面加入:Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Sub Form_Load() SetWindowPos hwnd, -1, 0, 0, 0, 0, 3 End Sub
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Sub Form_Load() SetWindowPos hwnd, -1, 0, 0, 0, 0, 3 End Sub
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Sub Timer1_Timer() Dim s As Long s = GetForegroundWindow() If s <> Me.hwnd Then SetForegroundWindow Me.hwnd End If End Sub
你可以这样一来试试:(个人意见) 'Form2: private sub cmd_Search_click() '其他代码 dim frmForm3 as Form3 set frmForm3 =new Form3 frmForm3.show vbModal '其他代码 end sub 这样一来的话,Form3总在Form2之前,并且你关闭Form3时,Form2不会消失.
要么就关闭3的时候, form1.hide form3.hide form2.show
'Form2: private sub cmd_Search_click() '其他代码 dim frmForm3 as Form3 set frmForm3 =new Form3 frmForm3.show 1,form2 '设为模式窗体 '其他代码 end sub
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
End Sub
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
End Sub
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
End Sub
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Timer1_Timer()
Dim s As Long
s = GetForegroundWindow()
If s <> Me.hwnd Then
SetForegroundWindow Me.hwnd
End If
End Sub
'Form2:
private sub cmd_Search_click()
'其他代码
dim frmForm3 as Form3
set frmForm3 =new Form3
frmForm3.show vbModal
'其他代码
end sub
这样一来的话,Form3总在Form2之前,并且你关闭Form3时,Form2不会消失.
form1.hide
form3.hide
form2.show
private sub cmd_Search_click()
'其他代码
dim frmForm3 as Form3
set frmForm3 =new Form3
frmForm3.show 1,form2 '设为模式窗体
'其他代码
end sub