Z Order of Controls in Delphi VCL
Get and set the Z Order of controls at runtime in Delphi VCL.

If you are looking for a FireMonkey solution see this post
Delphi provides a limited API for the Z order of controls.
You can bring a control to the front or send it to the back … that is all.
begin
Edit1.BringToFront;
Edit2.SendToBack;
end;
There is no API to get and set the Z order of a control.
Don’t panic – we can fix that using code that I provide in this post.
Demo Project

Full source code provided. See download link below.
The project demonstrated how to get and set the Z Order of controls.
You can change the Z order and watch the YELLOW TEdit move up and down through the Z Order.
The list on the right hand side shows the Z order of all controls on the form.
The Yellow TEdit that is being manipulated is highlighted in the list with “*******”
How does it work ?
The code uses the same BringToFront API repeatedly until everything is in the desired order. Its primitive but it works well enough.
It also deals with some other quirks, but the basic technique is based on brute force
Get Z Order of a control
This is the code that you write. Pretty easy
var
vZorder : integer;
begin
vZorder:= zzGetControlZOrder (MyEdit);
end;
Modify the Z Order of a control
Another one liner. The brute force happens behind the scenes
begin
zzSetControlZOrder (MyEdit, 10);
end;
Reposition a control on top of another control
// reposition Edit1 to be on top of Edit2
begin
zzSetControlZOrder (
Edit1
,zzGetControlZOrder (Edit2) + 1
);
end;
Reposition a control below another control
// reposition Edit1 to be on top of Edit2
begin
zzSetControlZOrder (
Edit1
,zzGetControlZOrder (Edit2) - 1
);
end;
Close enough
Some controls such as TLabel are always positioned at the back and their Z Order can not be changed. This can make it difficult for the zzSetControlZOrder function to reorder the control to exactly the right position, so it attempts to get it as close as possible to what you specify
Zero Based Z-Order
The Z Order is zero based, so the first control is # 0, the second control is #1.
Try to break it
You can throw any object that you like at the routines and they will survive. If you pass in something that does not have a Z-Order position, it wont do anything and it also wont crash, show an error or raise an error. The GET function will return -1. The SET function will return FALSE. I could have raised an error, but for the purposes that I built this it was more convenient to suppress all errors.
This works for …
- Controls on Forms, Panels and Frames.
- Tested for VCL in Delphi 10.1 Berlin and should work in many prior releases of Delphi
Download
DownloadVCL demo project with full source code
https://scotthollows.com/2016/12/04/scott-hollows-z-order-of-controls-in-delphi-vcl/
Z Order of Controls in Delphi VCL的更多相关文章
- Z Order of Controls in Delphi FireMonkey(Tom Yu的博客)
Get and set the Z Order of controls at runtime in Delphi FireMonkey. This is a follow on to my earli ...
- 自定义经纬度索引(非RTree、Morton Code[z order curve]、Geohash的方式)
自定义经纬度索引(非RTree.Morton Code[z order curve].Geohash的方式) Custom Indexing for Latitude-Longitude Data 网 ...
- Z Order(Copy From WIN32.HLP)
The Z order of a window indicates the window's position in a stack of overlapping windows. This wind ...
- delphi VCL研究之消息分发机制-delphi高手突破读书笔记
1.VCL 概貌 先看一下VCL类图的主要分支,如图4.1所示.在图中可以看到,TObject是VCL的祖先类,这也是Object Pascal语言所规定的.但实际上,TObject以及TObject ...
- delphi VCL组件同名继承
当我们在扩展一个 vcl 组件功能的时候,既想保留IDE中能拖动大小与直接设置属性的功能,又想减少写创建与释放代码和安装扩展后新组件的麻烦,那么本文中的方法,就非常实用了. 以给TStringGrid ...
- QT类库与Delphi VCL类库的体系结构对比——两者十分类似!
今天在看QT对象内存管理的一篇文章时:http://blog.csdn.net/dbzhang800/article/details/6300025想到了一个问题:就是QT类库体系结构与Delphi类 ...
- DELPHI (VCL及FMX[Firemonkey])启动时的欢迎窗口实现代码
VCL里面的的实现 program ZhouFamily; uses Vcl.Forms, Winapi.Windows, FrmZhouFamilyMainU in 'FrmZhouFamilyMa ...
- CSDN论坛 > Delphi > VCL组件开发及应用 DBLookupComboBox用法
(1)DataSource属性 该属性用于连接要编辑数据的主表数据源(2)DataField属性 该属性用于指定要编辑的数据字段名(3)ListSource属性 . 该属性用于 ...
- Delphi VCL类结构
随机推荐
- POJ 1985 - 树的直径
传送门 题目大意 给一颗n个点的树,求树的直径(最长的一条链) 题解 先随便找一个点u,dfs出离它最远的点v 于是有以下情况: 直径就是这条链 直径经过u,是这条链的延长 直径不经过u 只需要从v再 ...
- Risk Adaptive Information Flow Based Access Control
Systems and methods are provided to manage risk associated with access to information within a given ...
- android 流量统计
1 android通过架构流量统计TrafficStats类可以直接获得 获得总流量受理TrafficStats.getTotalRxBytes(), 获得总传出流量TrafficSt ...
- Struts2——(8)struts2中文件的上传
通过2种方式模拟单个文件上传,效果如下所示 开发步骤如下: 1.新建一个web工程,导入struts2上传文件所需jar,如下图 目录结构 2.新建Action 第一种方式 ...
- JavaScript动态广告弹出框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Modbus 通信协议详解
一.Modbus 协议简介 Modbus 协议是应用于电子控制器上的一种通用语言.通过此协议,控制器相互之间.控制器经由网络(例如以太网)和其它设备之间可以通信.它已经成为一通用工业标准.有了 ...
- 真的懂了:TCP协议中的三次握手和四次挥手(关闭连接时, 当收到对方的FIN报文时, 仅仅表示对方不在发送数据了, 但是还能接收数据, 己方也未必全部数据都发送对方了。相当于一开始还没接上话不要紧,后来接上话以后得让人把话讲完)
一.TCP报文格式 下面是TCP报文格式图: (1) 序号, Seq(Sequence number), 占32位,用来标识从TCP源端向目的端发送的字节流,发起方发送数据时对此进行标记. (2) 确 ...
- HTC VIVE 虚拟现实眼镜VR游戏体验
HTC的VIVE入手一段时间了,体验了几个免费的VR游戏,效果还不错,分享一下. 1. VIVE主要部件 VIVE的主要部件有3个,分别是头盔,两个无线控制手柄和两个定位器. 1.1 头盔 头盔整体照 ...
- [WebGL入门]十一,着色器编译器和连接器
注意:文章翻译http://wgld.org/,原作者杉本雅広(doxas).文章中假设有我的额外说明.我会加上[lufy:].另外.鄙人webgl研究还不够深入.一些专业词语,假设翻译有误.欢迎大家 ...
- 数学概念的提出(一) —— 熵的定义式 H(x)=-log2(p(x))
h(x)=−log2p(x) 考虑一个离散型随机变量 x,当我们观测到该变量的一个特定值,问此时我们通过该值获得的关于该变量的信息量是多少? 信息量可视为"意外的程度"(degre ...