Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you force a form to stay on top?

Posted on 2001-06-26
3
Medium Priority
?
233 Views
Last Modified: 2011-09-20
How do you force a form to stay on top of all forms in the same program, or on top of every other program. Are both possible?

thanks
0
Comment
Question by:kristofer
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 40 total points
ID: 6227192
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
Public Sub StayOnTop(frmForm As Form, fOnTop As Boolean)
 
  Const HWND_TOPMOST = -1
  Const HWND_NOTOPMOST = -2
 
  Dim lState As Long
  Dim iLeft As Integer, iTop As Integer, iWidth As Integer, iHeight As Integer
   
  With frmForm
    iLeft = .Left / Screen.TwipsPerPixelX
    iTop = .Top / Screen.TwipsPerPixelY
    iWidth = .Width / Screen.TwipsPerPixelX
    iHeight = .Height / Screen.TwipsPerPixelY
  End With
 
  If fOnTop Then
    lState = HWND_TOPMOST
  Else
    lState = HWND_NOTOPMOST
  End If
  Call SetWindowPos(frmForm.hwnd, lState, iLeft, iTop, iWidth, iHeight, 0)
End Sub
Private Sub Command1_Click()
    StayOnTop Me, True
End Sub
Private Sub Command2_Click()
    StayOnTop Me, False
End Sub
0
 
LVL 2

Author Comment

by:kristofer
ID: 6227220
thanks a lot, I was in a rush and that was just what I needed!
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 6227230
ya, it's ok!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question