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类结构
随机推荐
- 推荐:一个写的相当好的介绍C++单元测试框架Google Test (gtest) 教程
原文来自:http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html 虽然有点晚了,还是一口气读完了全部文章.作者言简意赅和明快的风格 ...
- hexo改造
一直在思考网站分类的问题. 用hexo默认的分类,并不利于用户直观的感受到网站的内容意图,尤其是hexo首页进入后是最近发表的文章列表.然后考虑开启多个hexo服务,每个hexo服务是一个分类内容,如 ...
- MacOS系统升级后,IDEA的SVN不好用的问题
最近给MacOS升级到10.13.2(High Sierra). 结果,发现IDEA的SVN不好用了. 提示如下: 查看IDEA的Subversion设置应该是这个样子的: 但是,设置后没有效 ...
- OpenCV dll 源码调试—附加到进程
使用CMake可以生成OpenCV源码的解决方案,然后就可以对OpenCV函数进行修改,功能剪切等操作了,对这部分内容感兴趣的可以浏览一下上一篇文章:CMake生成OpenCV解决方案&&am ...
- 参数的范数正则/惩罚(parameter norm penalties)
1. L2 范数 J~(w;X,y)=J(w;X,y)+α2wTw J 表示的是原始的目标函数,J~ 则是二范数约束后的新的目标函数. 则根据梯度下降算法有: ∇wJ~=∇wJ+αw w←w−ϵ∇wJ ...
- Tagging Physical Resources in a Cloud Computing Environment
A cloud system may create physical resource tags to store relationships between cloud computing offe ...
- delphi xe 之路(14)使用FireMonkeyStyle(一共30篇)
FireMonkey使用Style来控制控件的显示方式. 每个控件都有一个StyleLookup属性,FireMonkey就是通过控件的这个属性来在当前窗体的StyleBook控件中查找匹配的Styl ...
- Leetcode 171 Excel Sheet Column Number 字符串处理
本质是把26进制转化为10进制 A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 class Solution ...
- 简述WPF中的画刷(Brush)
原文:简述WPF中的画刷(Brush) -------------------------------------------------------------------------------- ...
- Linux性能测试 /proc目录
/proc文件系统 - 各种内核信息/proc目录下文件提供了很多不同硬件设备和内核的详细信息.更多详情参见Linux kernel /proc.一般/proc例如: [root@SM155 proc ...