Results 1 to 7 of 7

Thread: Keep a FORM on top of another FORM

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    116

    Exclamation

    How can I force a form to stay in the background of
    another form?

    Thanks
    0101011001000010
    01101111011011100110110001101001011011100110010101110010

  2. #2
    Junior Member
    Join Date
    Mar 2000
    Location
    Ocotlan, Jalisco, Mexico
    Posts
    18
    This is a how to keep a VB form window always on top, but only of the selected window, not above ALL windows. Instead of SetWindowPos, it uses SetWindowWord. This lets you create a floating toolbar that stays above its app's window without staying on top of ALL windows. Very handy for that professional look.

    Declare Sub SetWindowWord Lib "USER32" (ByVal hWnd, ByVal nCmd, ByVal nVal)
    Const SWW_hParent = (-8)

    Form_Load of the form that you want to keep on top. Set it about form1.

    Sub Form_Load ()
    SetWindowWord hWnd, SWW_hParent, form1.hWnd
    End Sub

    Form_Unload of the from you want to keep on top this is for cleaning up.

    Sub Form_Unload (Cancel As Integer)
    SetWindowWord hWnd, SWW_hParent, 0
    End Sub

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Not sure exactly what you are after here...

    Are you wanting to make FORM1 always infront of FORM2?

    Or do you want to make FORM2 always behind FORM1?

    Believe it or not there is a subtle difference

    If its the former then you can use the SetWindowPOS function to make FORM1 the topmost form which places it ontop of any other forms you currently have accept Msgboxes

  4. #4
    Guest
    You could also modal a form.

    Code:
    Form1.Show vbModal
    This will keep the form on top of every other form, and also disable all forms behind it allowing access only to the form on top.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    ZOrder Method
          
    
    Places a specified MDIForm, Form, or control at the front or back of the z-order within its graphical level. Doesn't supportnamed arguments.
    
    Syntax
    
    object.ZOrder position
    
    The ZOrder method syntax has these parts:
    
    Part Description 
    object Optional. Anobject expression that evaluates to an object in the Applies To list. If object is omitted, the form with thefocus is assumed to be object. 
    Position  Optional. Integer indicating the position of object relative to other instances of the same object. If position is 0 or omitted, object is positioned at the front of the z-order. If position is 1, object is positioned at the back of the z-order. 
    
    
    Remarks
    
    The z-order of objects can be set atdesign time by choosing the Bring To Front or Send To Back menu command from the Edit menu.
    
    Within an MDIForm object, ZOrder sendsMDI child forms to either the front or the back of the MDI client area, depending on the value of position. For an MDIForm or Form object, ZOrder sends the form to either the front or the back of the screen, depending on the value of position. As a result, forms can be displayed in front of or behind other running applications.
    
    Three graphical layers are associated with forms andcontainers. The back layer is the drawing space where the results of the graphics methods are displayed. Next is the middle layer where graphical objects and Label controls are displayed. The front layer is where all nongraphical controls like CommandButton, CheckBox, or ListBox are displayed. Anything contained in a layer closer to the front covers anything contained in the layer(s) behind it. ZOrder arranges objects only within the layer where the object is displayed.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    116

    Thumbs up

    That's very cool and efficient Mr. Gates. You
    are a PRO.
    0101011001000010
    01101111011011100110110001101001011011100110010101110010

  7. #7
    Guest
    The ZOrder method, as HeSaidJoe gave, is also good.

    Here is an example of how to use it:

    Code:
    Private Sub Command1_Click()
    'Form1's Command Button:
    Form1.ZOrder vbSendToBack
    Form2.ZOrder vbBringToFront
    End Sub
    
    Private Sub Command1_Click()
    'Form2's Command Button:
    Form1.ZOrder vbBringToFront
    Form2.ZOrder vbSendToBack
    End Sub

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