Results 1 to 6 of 6

Thread: Always on top again

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    39

    Question

    I'm sure this one has been asked a million times already, but I need to know how to keep a form on top. I have a large form on screen, when I click a button a smaller form pops up and hovers about a bit, but when I click on a control on the main form again the smaller one disappears, I need it to stay visible until other events take place. Any ideas anyone ?

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    try:
    Code:
    Form2.Show vbModal
    and this will keep your second form on top util you close it down.

    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    39

    Smile

    Thanks, It does keep it open. However one problem, it doesn't allow me to return focus back to the main form so I can continue to type stuff in on the main form.

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    If have a form open then call a form like:
    form2.show , form1

    form1 will act like MDIForm, except form2 can go beyond form1's edges

    but it will stay above form1 at all times

  5. #5
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    OK

    Try this:

    Code:
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_SHOWWINDOW = &H40
    Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Public Sub MakeNormal(Handle As Long)
    	'// Replaces the window in the ZOrder
    	SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
    End Sub
    
    Public Sub MakeTopMost(Handle As Long)
    	'// Sets the window in the ZOrder
    	SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
    End Sub
    then to make Form2 stay on top use:

    Code:
    MakeTopMost Form2.hwnd
    and to return it to its normal state use:

    Code:
    MakeNormal Form2.hwnd
    Hope this helps

    Shaun


    [Edited by S@NSIS on 08-22-2000 at 08:13 AM]
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Or if you just want the form to be on top of your main form and not on top of all program windows you could just show it like this:
    Code:
    From2.Show vbModeLess, Me 'or the form you want it to be on top of
    Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width