ToTop, ToBack Methods, OnTop Property

Purpose

ToTop places the Form at the top of the Z order. ToBack places the Form at the bottom of the Z order.

Syntax

Form.ToBack

Form.ToTop

Form.OnTop [ = Boolean ]

Description

The ToTop and ToBack methods use the SetWindowPos function to change the Z order of Form. Child, pop-up, and top-level windows are ordered according to their appearance on the screen. The topmost window receives the highest rank and is the first window in the Z order. If a Form identifies a topmost window, with ToBack the window loses its topmost status and is placed at the bottom of all other windows.

The OnTop property sets the topmost state of a window. OnTop places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated; using the ToTop method does NOT set the corresponding OnTop property to True.

Example

OpenW 1 : Win_1.Caption = "Window 1"

Ocx Command cmd(1) = "Send to Back", 10, 10, 120, 22

Ocx Label lbl(1) = "", 10, 40, 120, 14

OpenW 2 : Win_2.Caption = "Window 2"

Ocx Command cmd(2) = "Send to Back", 10, 10, 120, 22

Ocx Label lbl(2) = "", 10, 40, 120, 14

Do : Sleep  : Until Win_1 Is Nothing Or Win_2 Is Nothing

CloseW 1 : CloseW 2

 

Sub cmd_Click(Index%)

If Index% = 1 Then Win_2.ToTop // or Win_2.OnTop = True

If Index% = 2 Then Win_2.ToBack (* or Win_1.OnTop = True *) : Win_1.ToTop

EndSub

 

Sub Win_1_Activate

cmd(2).Caption = ""

cmd(1).Caption = "Send to Back"

lbl(1).Caption = "Window 1 on Top"

EndSub

 

Sub Win_2_Activate

cmd(1).Caption = ""

cmd(2).Caption = "Send to Back"

lbl(2).Caption = "Window 2 on Top"

EndSub

Remarks

The ZOrder method changes the z-order as well.

See Also

Form

{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}