devxlogo

Make a Form Stay on Top

Make a Form Stay on Top

You can make a form always remain above others, even when it does not have focus. Use this code in a BAS module:

 #If Win16 Then	Declare Sub SetWindowPos Lib "User" ( _		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)#Else	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) As Long#End IfPublic Const SWP_NOMOVE = &H2Public Const SWP_NOSIZE = &H1Public Const HWND_TOPMOST = -1Public Const HWND_NOTOPMOST = -2

Use this code to make the form stay on top in the form module:

 SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, _	SWP_NOMOVE + SWP_NOSIZE

Use this code to make the form no longer stay on top in the form module:

 SetWindowPos Parent.hwnd, HWND_NOTOPMOST, _	 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

In 16-bit systems, use the 16-bit equivalents.

See also  Small Business Strategies with Venmo
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist