The following code example is using the SetWindowPos method call of the user32.dll api.
Option Explicit Private Const HWND_BOTTOM As Long = 1 Private Const HWND_NOT_TOP_MOST As Long = -2 Private Const HWND_TOP As Long = 1 Private Const HWND_TOP_MOST As Long = -1 Private Const SWP_NO_MOVE As Long = &H2 Private Const SWP_NO_SIZE As Long = &H1 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) Declare Function GetActiveWindow& Lib "user32" () Public Sub MakeWindowAlwaysTop(ByVal hWnd As Long) SetWindowPos hWnd, HWND_TOP_MOST, 0, 0, 0, 0, SWP_NO_MOVE + SWP_NO_SIZE End Sub Public Sub MakeWindowNotTop(ByVal hWnd As Long) SetWindowPos hWnd, HWND_NOT_TOP_MOST, 0, 0, 0, 0, SWP_NO_MOVE + SWP_NO_SIZE End Sub
Suppose if you want to make your form named from1 always on top then you can use call the following method on the form load event:
Private sub form1_load() MakeWindowNotTop Me.hWnd End sub