Source code "Always On Top" with Visual Basic programming

This time I want to share a trick on how to make a form stay always on top. This trick is very trivial, but in fact I often use this trick to work on many projects (especially completed several blogs at once). With this method, you do not need to move from one program to another program just to make a copy and paste action.

Now, open your
Visual Basic program and do the instructions as shown below!

1. Open Form1 code window.

SetWindowPos Me.Hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE

Copy and paste the above code in Form1 code window (like in the picture below).

Source code is Always On Top

2. Add a module's window (in the menu bar, click Project > Add Module)

Public 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

Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2


Copy and paste the above code in module1 code window.

We can complete the complex job with quickly and accurately where sometimes it can be done by simple things. Hopefully this trick is useful for you.


Keyword: Visual Basic Programming, Example Source Code of Always On Top

You may also like: