form that's always-on-top

Posted on 2003-03-28
Medium Priority
Last Modified: 2010-05-01
This is a pretty simple question:
My main form opens another small form. I want the smaller form to always be on top of the main form until the smaller one is closed out. In VB .NET, I think a form has an "AlwaysOnTop" property, but I'm working in VB6 right now and I can't figure out how to do it.
Question by:vitanza
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

SpineyNorman earned 80 total points
ID: 8227548
If Form1 is the name of the smaller form you are showing, then
you can use

Form1.Show vbModal


Expert Comment

ID: 8227752
If you only want your form to be at the top of other forms within your app, rather than being on top of all windows (including other apps):

frmTop.Show vbModeless, frmParent

This will bring the form above its parent (specified as the second parameter).

If a MessageBox appears below the TopMost window and you want it above it instead, then use the vbSystemModal constant in the MsgBox function's Style attribute (this forces the MessageBox to show on top of the AlwaysOnTop form).

Expert Comment

ID: 8227819

'you need to use API functions:

'Win32API functions
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

'Win32API constants
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2

Private Sub Command1_Click()
    SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub

Private Sub Command2_Click()
    SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

752 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