Keeping forms at the front of the screen

I'm trying to write a simple calculator program in VB5 that is always on top of other windows, so that I can copy its results into other applications without the calculator disappearing into the background.

I know it's just a simple property setting with Delphi, but I'm clueless as to how this can be done with VB.
Phaedra74Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
Add this to the form module...

   Private 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

   Property Let TopMost(sTopmost As Boolean)

      Const HWND_TOPMOST = -1
      Const HWND_NOTOPMOST = -2

     Select Case sTopmost
     Case Is = True
        Call SetWindowPos(Me.hWnd, HWND_TOPMOST, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0)
     Case Is = False
        Call SetWindowPos(Me.hWnd, HWND_NOTOPMOST, Me.Left \ Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0)
     End Select
 
   End Property

This will add a property to the form so you can use simple code like this to put the form on top...

   formname.TopMost = True

.... and code like this to change it back to 'standard' mode...

   formname.TopMost = False
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.