Form Always On Top

Home

'**************************************
' Name: Always On Top
' Description:Keeps Your Form On Top
' This Is Really Kewl Because You Can Just
' Use A False attribuite To Set it as Not
' on top instead of using 2 functions
' By: Adam Jacob Muller
'
' This code is copyrighted and has limited warranties.
' Please see http://www.Planet-Source-Code.com/xq/ASP/
' txtCodeId.2651/lngWId.1/qx/vb/scripts/ShowCode.htm
' for details.
'**************************************

Public Sub AlwaysOnTop(myfrm As Form, SetOnTop As Boolean)
    If SetOnTop Then
        lFlag = HWND_TOPMOST
    Else
        lFlag = HWND_NOTOPMOST
    End If
    SetWindowPos myfrm.hwnd, lFlag, _
    myfrm.Left / Screen.TwipsPerPixelX, _
    myfrm.Top / Screen.TwipsPerPixelY, _
    myfrm.Width / Screen.TwipsPerPixelX, _
    myfrm.Height / Screen.TwipsPerPixelY, _
    SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub

' for example, if you're in a form called 'Form1' simply type:
AlwaysOnTop Form1, True