I have an application that runs in the background and on command shows windows applications to the user.
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.