Results 1 to 6 of 6

Thread: Form2 on top of Form1

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Form2 on top of Form1

    How can I make Form2 show on top of Form1 and have it stay there. I tried using top-most and that works however it also makes Form2 on top of every other Form which I don't want


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    gibra
    Guest

    Re: Form2 on top of Form1

    From Form1

    Code:
    Private Sub Command1_Click()
        Form2.Show , Me
    End Sub
    Remember that, in this case:
    1. when you minizime Form1, Form2 also will be minimized.
    2. when you close Form1, Form2 also will be close.

  3. #3
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    765

    Re: Form2 on top of Form1

    Sounds like the behaviour of a dialog to me.

    Code:
    Form2.Show vbModal, Me
    Regards, Phill W.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Form2 on top of Form1

    Form2.Show vbModal, Me won't work as it blocks user's from using controls on Form1 but would be the correct way if Form2 was to be like a modal Form

    Form2.Show , Me works correctly


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,254

    Re: Form2 on top of Form1

    Why not just use the Setparent API

    Code:
    Option Explicit
    Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Private Sub Command1_Click()
       Form2.Show
       SetParent Form2.hWnd, Me.hWnd
    End Sub
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Form2 on top of Form1

    Quote Originally Posted by ColinE66 View Post
    Why not just use the Setparent API

    Code:
    Option Explicit
    Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Private Sub Command1_Click()
       Form2.Show
       SetParent Form2.hWnd, Me.hWnd
    End Sub
    See my other Thread http://www.vbforums.com/showthread.p...=1#post4899547


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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