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类结构
随机推荐
- MVVM、MVVMLight、MVVMLight Toolkit之我见
原文:MVVM.MVVMLight.MVVMLight Toolkit之我见 我想,现在已经有不少朋友在项目中使用了MVVMLight了吧,如果你正在做WPF,Silverlight,Windows ...
- 初探python+selenium
由于公司网络管管控严格,服务器上访问外网需要进行身份认证(按理说递交个申请给开放相关域名外网访问就好,无奈不给通过,又想马儿跑又不给马吃草),正好前一阵撸课程的时候看到selenium可以实现自动化, ...
- 实现在 .net 中使用 HttpClient 下载文件时显示进度
在 .net framework 中,要实现下载文件并显示进度的话,最简单的做法是使用 WebClient 类.订阅 DownloadProgressChanged 事件就行了. 但是很可惜,WebC ...
- linux下安装sqlite3
1.介绍:sqlite3是linux上的小巧的数据库,一个文件就是一个数据库.2.安装: 要安装sqlite3,可以在终端提示符后运行下列命令: sudo apt-get install sqli ...
- CUDA中block和thread的合理划分配置
CUDA并行编程的基本思路是把一个很大的任务划分成N个简单重复的操作,创建N个线程分别执行执行,每个网格(Grid)可以最多创建65535个线程块,每个线程块(Block)一般最多可以创建512个并行 ...
- Windows 10 应用创建模糊背景窗口的三种方法
原文 Windows 10 应用创建模糊背景窗口的三种方法 现代的操作系统中创建一张图片的高斯模糊效果非常容易,不过如果要在窗口中获得模糊支持就需要操作系统的原生支持了.iOS/Mac 和 Windo ...
- 参数的范数正则/惩罚(parameter norm penalties)
1. L2 范数 J~(w;X,y)=J(w;X,y)+α2wTw J 表示的是原始的目标函数,J~ 则是二范数约束后的新的目标函数. 则根据梯度下降算法有: ∇wJ~=∇wJ+αw w←w−ϵ∇wJ ...
- 对于ado.net dataProvider的介绍
学习刘皓的 ADO.NET入门教程(二)了解.NET数据提供程序 而来 这篇文章很一般,主要是对dataProvider做了个简单的介绍.因为在该系列文章中提到,ado.net主要有两部分 dataP ...
- 希尔伯特空间(Hilbert Space)
欧氏空间 → 线性空间 + 内积 ⇒ 内积空间(元素的长度,元素的夹角和正交) 内积空间 + 完备性 ⇒ 希尔伯特空间 0. 欧几里得空间 欧氏空间是一个特别的度量空间,它使得我们能够对其的拓扑性质, ...
- 离散时间信号常见函数的实现(matlab)
1. 单位样本序列 δ(n−n0)={1,n=n00,n≠n0 function [x, n] = impseq(n0, n1, n2) n = n1:n2; x = [n == n0]; 2. 单位 ...