21 | 09 | 2017

Form Always on Top

Use the code below to set the requested form always on top.

{code lang:vbnet lines:false hidden:false}
Option Explicit

'****************************************
'*** Code from VisibleVisual.com ********
'****************************************

Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVEOrSWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Declare Function SetWindowPos Lib "user32" (ByValhwndAsLong, ByValhWndInsertAfterAsLong, ByValxAsLong, ByValyAsLong, ByValcxAsLong, ByValcyAsLong, ByValwFlagsAsLong) As Long
Public Function SetTopMostWindow(hwndAsLong, TopmostAsBoolean) As Long
If Topmost = True Then 'Makethewindowtopmost
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
SetTopMostWindow = False
End If
End Function{/code}

To enable the FORM ON TOP enter:

{code lang:vbnet lines:false hidden:false}Dim lR As Long
lR = SetTopMostWindow(Me.hwnd, True){/code}

To disable enter

{code lang:vbnet lines:false hidden:false}Dim lR As Long
lR = SetTopMostWindow(Me.hwnd, False){/code}

Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2355337
Latest Articles