Results 1 to 6 of 6

Thread: Always On Top Between Form [Resolved]

  1. #1

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212

    Always On Top Between Form [Resolved]

    Hello guys,
    How to make Form2 always on top from Form1 BUT I can still click Command1(Command Button) at Form1.

    Please help me.

    Thanks.
    Last edited by g-mie; Mar 22nd, 2004 at 09:13 PM.

  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    This must the most asked question on here, do a search.

    VB Code:
    1. Private Declare Function SetWindowPos Lib "user32" _
    2. (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
    3. ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
    4. ByVal cy As Long, ByVal wFlags As Long) As Long
    5.  
    6. Const SWP_NOMOVE = &H2
    7. Const SWP_NOSIZE = &H1
    8. Const SWP_SHOWWINDOW = &H40
    9. Const SWP_NOACTIVATE = &H10
    10. Const HWND_NOTOPMOST = -2
    11. Const HWND_TOPMOST = -1
    12.  
    13. Private Sub FormOnTop(Handle As Integer, OnTop As Boolean)
    14.  
    15. Dim wFlags As Long
    16. Dim PosFlag As Long
    17.  
    18. wFlags = SWP_NOMOVE Or SWP_NOSIZE Or _
    19. SWP_SHOWWINDOW Or SWP_NOACTIVATE
    20.  
    21. Select Case OnTop
    22.     Case True
    23.         PosFlag = HWND_TOPMOST
    24.        
    25.     Case False
    26.         PosFlag = HWND_NOTOPMOST
    27.        
    28. End Select
    29.  
    30. SetWindowPos Handle, PosFlag, 0, 0, 0, 0, wFlags
    31.  
    32. End Sub
    33.  
    34. Private Sub Form_Load()
    35.  
    36. FormOnTop Me.hwnd, True
    37.  
    38. End Sub
    39.  
    40. Private Sub Form_Unload(Cancel As Integer)
    41.  
    42. FormOnTop Me.hwnd, False
    43.  
    44. End Sub

  3. #3

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212
    Keithuk,
    I search about it but cannot find the suitable code. Anyway, thank you for your help.


  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Keithuk's suggestion is the normal way of doing what you ask, but another way is to put this code in Form2.


    VB Code:
    1. Dim ctl As Control
    2.    
    3.     For Each ctl In Form1.Controls
    4.         ctl.Enabled = False
    5.     Next
    6.    
    7.     Form1.Command1.Enabled = True

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    Thanks Marty.

    I assumed that he would put the code in Form2 because he wants Form2 on top.

    Thou its wrong to assume. It makes an Ass out of U and Me, AssUMe.

  6. #6

    Thread Starter
    Addicted Member g-mie's Avatar
    Join Date
    Jan 2004
    Location
    EarTh
    Posts
    212
    Actually, I got my own solution already
    VB Code:
    1. 'place this code in Form1
    2. 'Form2 will be on top of Form1
    3. 'Command Button (or others object) on Form1 still can be click
    4.  
    5. Private Sub Command1_Click()
    6. Form2.Show , Form1
    7. End Sub

    Thanks again guys.

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