Chris's Event Programming with Visual Basic course.

Contents
Introduction

Conventions

Starting VB3

The development environment

Help Documentation

The "On-line" Tutorial

Starting a new project

Making an application

Working with Forms

Modal forms

Multiple Document Interface (MDI)

Building the interface

Menus 

Tool Bars & Control Arrays

Building a Control Array

Z Order

Custom controls

Handling Data

Input Boxes

Message Boxes

Error Trapping

The Data Manager

Data Aware Components

Debugging code

Compilation of code 

Z Order
This is commonly used to determine the sequence by which graphical objects are arranged, there are three graphical layers associated with forms and containers.  The back layer is the drawing space, where the results of the graphics methods appear. Next is the middle layer where graphical controls and labels appear.  The front layer is where all non-graphical controls like command buttons, check boxes, and file controls appear.  Anything in one layer covers anything in the layer behind.  The ZOrder method arranges controls only within the layer where the control appears. This can be used to dynamically determine which control is to be used, for example forms could be re-ordered  or, controls might be re-ordered on a form.  Drag a command button onto Form2 and name it Command1, set the Index property to 0, (this indicates that the control is an array). Now paste the following code into Form2:

Sub Form_Load ()
 Dim I ' Declare variable.
 For I = 1 To 5
  Load Command1(I)    ' Load new command button.
  Command1(I).Left = Command1(I - 1).Left + 250 ' Change position.
  Command1(I).Top = Command1(I - 1).Top + 250
  Command1(I).Caption = "Command" & I + 1  ' Change caption.
  Command1(I).Visible = True    ' Make visible.
 Next I
End Sub

Sub Command1_Click (Index As Integer)
 Command1(Index).ZOrder 0     ' Position button to front.
End Sub

Running the application, (remember to minimise form1 to activate form2 in this example) produces a form with an array of command boxes, any of which can be brought to the front by the Z-order method on a click event.

This should not be confused with Tab order which is not set by a method but is a property that each control added to a form acquires. Save the project as VB3aa4.mak, (where aa is your initials).
 

Visual Basic and all other Microsoft products mentioned in this series are trademarks of the Microsoft Corporation.