简体   繁体   English

如何在vb.NET中带到前窗

[英]How to bring to front window in vb.NET

I have an application that runs in the background and on command shows windows applications to the user. 我有一个在后台运行的应用程序,并且在命令中向用户显示Windows应用程序。

My problem is that I can't get the windows to be on the front and on top of ALL the other windows (Browser(Usually) , other applications etc) 我的问题是我无法使这些窗口位于所有其他窗口的顶部和顶部(浏览器(通常),其他应用程序等)

I used TopMost=True , BringToFront() , Form.Activate() , Form.ShowDialog() etc and it still not working for me. 我使用了TopMost=TrueBringToFront()Form.Activate()Form.ShowDialog()等,但它仍然对我不起作用。

I managed to get it in front of all other app but only at the first window. 我设法将它放在所有其他应用程序的前面,但仅限于第一个窗口。 EX: I run the app in the background, and the first window is shown on top of all the others.(The windows basically shown on top only after reset) The user finished with this window and closes it. 例:我在后台运行该应用程序,第一个窗口显示在所有其他窗口的顶部(这些窗口基本上仅在重置后显示在顶部)。用户完成此窗口并关闭它。 After a while a second window is supposed to be shown on top of all but its not at the top of all. 一段时间后,应该在所有窗口的顶部显示第二个窗口,但不在所有窗口的顶部。

What else can I try? 我还能尝试什么? Do you have an idea of what can "block" my application so its not on top? 您是否知道什么可以“阻止”我的应用程序,从而使其不在顶部?

      Public Function ChooseDir() As String        
      Dim sRes As String = ""

        Using folders As frmFolderBrowser = New frmFolderBrowser()
            folders.ShowDialog()
            sRes = folders.StrPathValue
        End Using
      ChooseDir = sRes

      End Function



    Private Sub frmFolderBrowser_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load        
    If DialogResult.OK = FolderBrowserDialog.ShowDialog() Then
        strPath = FolderBrowserDialog.SelectedPath
    End If
    Me.Close()

End Sub

This should work for you: 这应该为您工作:

MakeTopMostWindow(Me.Handle.ToInt64, True)
Application.DoEvents()
MakeTopMostWindow(Me.Handle.ToInt64, False)

where this is defined elsewhere 在其他地方定义的地方

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

Friend Sub MakeTopMostWindow(ByVal hwnd As Int64, ByVal MakeTopMostFlag As Boolean)

    Dim HWND_TOPMOST As Integer
    If MakeTopMostFlag Then
        HWND_TOPMOST = -1
    Else
        HWND_TOPMOST = -2
    End If

    Dim SWP_NOMOVE As Integer = &H2
    Dim SWP_NOSIZE As Integer = &H1
    Dim TOPMOST_FLAGS As Integer = SWP_NOMOVE Or SWP_NOSIZE
    Try
        SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS)
    Catch ex As Exception 
    End Try

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM