Applies to VB4+ |
A topmost window remains above other windows even when it is inactive. The SetTopmost procedure turns a form into a topmost window or returns a topmost form to normal:
SetTopmost requires these API declarations (available in Win32.tlb):
To create a topmost window, call SetTopmost with True as the second argument:
SetTopmost frmSplash, True
To return a topmost window to normal, use False instead:
SetTopmost frmSplash, False
If you want a form to float immediately when it loads, call SetTopmost in the Form_Load event:
Private Sub Form_Load() SetTopmost Me, True End Sub
Note that Visual Basic has a rather annoying bug: If you minimize the IDE while your program is running, topmost forms don't float anymore.
The following event procedure illustrates how you might implement an "Always on Top" menu command:
Private Sub mnuAlwaysOnTop_Click() Static Topmost As Boolean Topmost = Not Topmost SetTopmost Me, Topmost mnuAlwaysOnTop.Checked = Topmost End Sub
Microsoft Knowledge Base
Copyright © 2001 Rising Productions. Last update: June 28