How to prevent a form with TopMost property set to true from being on top of windows that didn’t create it
When you set a form’s TopMost property to true, that form will be on top of all windows on your desktop including those that are not part of you application
The code below prevents that.
Public Class frmTopMostSetTrue
#Region " Fields "
Const WM_ACTIVATEAPP As Integer = &H1C
#End Region
Protected Overrides Sub WndProc(ByRef m As Message)
Select Case m.Msg
'The WM_ACTIVATEAPP message occurs when the application
'becomes the active application or becomes inactive
Case WM_ACTIVATEAPP
'The WParam value identifies what is occurring.
Dim active As Boolean = m.WParam.ToInt32 <> 0
If Not active Then Me.Hide() Else Me.Show()
End Select
'We call base.WndProc to make sure that the message is processed by Windows
MyBase.WndProc(m)
End Sub
End Class