很多这样的例子,算后面的form被选中,前面的form还在前面。
根对话框不一样,对话框,在前面的窗口不去掉的情况下还无法激活后面的form。

解决方案 »

  1.   

    参考:Option ExplicitPrivate 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 Const SWP_NOMOVE = 2
    Private Const SWP_NOSIZE = 1
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_SHOWWINDOW = &H40
    Private Const wFlags = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE'始终放在前面
    Private Sub KeepOnTop(frmForm As Form)
       SetWindowPos frmForm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, wFlags
    End Sub'取消
    Private Sub RemoveOnTop(frmForm As Form)
       SetWindowPos frmForm.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags
    End Sub
      

  2.   

    调用例子:Private Sub Command1_Click()
        KeepOnTop Me
    End SubPrivate Sub Command2_Click()
        RemoveOnTop Me
    End Sub
      

  3.   

    我在Modules里边写下面的代码为什么出错阿?
        Load Form2
        Form2.Show 0, Form1
      

  4.   

    我说一个本办法,假如想一直让Form2在Form1的前面,在Form1的activate事件中

       if not Form2 is nothing and Form2.visible=true then
          Form2.Zorder
       end if
    这样,就可以了。
    不知道是不是你想要的效果。