ZOrder Method

Applies To

CheckBox control, ComboBox control, CommandButton control, Image control, Label control, ListBox control, MultiPage control, OptionButton control, ScrollBar control, SpinButton control, TabStrip control, TextBox control, ToggleButton control.

Description

Places the object at the front or back of the z-order.

Syntax

object.ZOrder( [zPosition])

The ZOrder method syntax has these parts:

Part

Description

object

Required. A valid object.

zPosition

Optional. A control's position, front or back, in the container's z-order.


Settings

The settings for zPosition are:

Constant

Value

Description

fmTop

0

Places the control at the front of the z-order. The control appears on top of other controls (default).

fmBottom

1

Places the control at the back of the z-order. The control appears underneath other controls.


Remarks

The z-order determines how windows and controls are stacked when they are presented to the user. Items at the back of the z-order are overlaid by closer items; items at the front of the z-order appear to be on top of items at the back. When the zPosition argument is omitted, the object is brought to the front.

In design mode, the Bring to Front or Send To Back commands set the z-order. Bring to Front is equivalent to using the ZOrder method and putting the object at the front of the z-order. Send to Back is equivalent to using ZOrder and putting the object at the back of the z-order.

This method does not affect content or sequence of the controls in the Controls collection.

Note You can't Undo or Redo layering commands, such as Send to Back or Bring to Front. For example, if you select an object and click Move Backward on the shortcut menu, you won't be able to Undo or Redo that action.

See Also

SetFocus method.

Example

The following example sets the z-order of a TextBox, so the user can display the entire TextBox (by bringing it to the front of the z-order) or can place the TextBox behind other controls (by sending it to the back of the z-order).

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • Three TextBox controls named TextBox1 through TextBox3.
  • A ToggleButton named ToggleButton1.
    Private Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
        TextBox2.ZOrder (fmTop)          'Place TextBox2 on Top of z-order
        
        'Update ToggleButton caption to identify next state
        ToggleButton1.Caption = "Send TextBox2 to back"
    Else
        TextBox2.ZOrder (1)              'Place TextBox2 on Bottom of z-order
        
        'Update ToggleButton caption to identify next state
        ToggleButton1.Caption = "Bring TextBox2 to front"
    End If
    End Sub
    
    Private Sub UserForm_Initialize()
    'Set up text boxes to show z-order in the form
    TextBox1.Text = "TextBox 1"
    TextBox2.Text = "TextBox 2"
    TextBox3.Text = "TextBox 3"
    
    TextBox1.Height = 40
    TextBox2.Height = 40
    TextBox3.Height = 40
    
    TextBox1.Width = 60
    TextBox2.Width = 60
    TextBox3.Width = 60
    
    TextBox1.Left = 10
    TextBox1.Top = 10
    
    TextBox2.Left = 25      'Overlap TextBox2 on TextBox1
    TextBox2.Top = 25
    
    TextBox3.Left = 40      'Overlap TextBox3 on TextBox2, TextBox1
    TextBox3.Top = 40
    
    ToggleButton1.Value = False
    ToggleButton1.Caption = "Bring TextBox2 to Front"
    ToggleButton1.Left = 10
    ToggleButton1.Top = 90
    ToggleButton1.Width = 50
    ToggleButton1.Height = 50
    
    End Sub