如何检查"Z位置"是否正确?在MDI应用程序中的形式? [英] How to check the "Z-position" of form in a MDI application?

查看:64
本文介绍了如何检查"Z位置"是否正确?在MDI应用程序中的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Delphi中创建了MDI应用程序.假设我的应用程序中有一堆MDIChild表单,这些表单在屏幕上可见.我想在这些表单上执行循环,并检查每个表单以什么顺序显示在屏幕上.

I have created MDI application in Delphi. Lets assume that I have a bunch of MDIChild forms in my application which are visible on the screen. I would like to perform a loop on those forms and check in what order each of the forms is displayed on the screen.

例如,如果我有3种MDICHild形式:

For example if I have 3 MDICHild forms:

FormA FormB FormC

FormB 部分重叠 FormA FormC 部分重叠FormB

FormB partly overlaps FormA and FormC partly overlaps FormB

我要标记其Z属性(深度)如下:

I want to mark their Z property (deepth) as follows:

FormB.Z = 2 // that form is between FormA and FormC
FormA.Z = 3 // that form's distance is longest from user, form is overlapped by FormB and 
FormC.Z = 1 // that form is at the top of all forms in my application 

感谢您的时间.

推荐答案

J 的答案通过Screen.Forms循环.正如您从评论中看到的那样,它包含应用程序中的所有表单,包括非MDI表单.您可以手动过滤主窗体和关于"框,但这很麻烦,对于其他窗体,您还需要执行相同的操作.我真的不喜欢这样做,因为它似乎很容易出错.

J's answer loops through Screen.Forms. This contains all forms in the application, including non-MDI ones, as I see you found from your comment. You can filter your main form and About box manually, but that's messy, and you'll also need to do the same thing for other forms. I really don't like having to do that because it seems rather error-prone.

您的问题是,您只想知道父级中MDI子窗体的z顺序,在这种情况下,有一个更好的解决方案.

Your question says you only want to know the z-order of MDI child forms within the parent, and in this case there's a much better solution.

MDI子级在MDI父窗体的MDIChildren属性中按z排序的顺序列出.查找Z深度的代码如下所示(未经测试):

MDI children are listed in z-sorted order in the MDI parent form's MDIChildren property. The code to find the Z depth would look something like this (untested):

function FindChildDepth(Child : TForm) : Integer;
var
  i : Integer;
begin
  Result := -1; // Form not found
  for i := 0 to MDIChildCount-1 do
  begin
    if (MDIChildren[i] == Child) then
    begin
      Result := i;
      Exit;
    end;
  end;
end;

这应该返回0到n-1之间的子项的深度,其中0是top,如果在MDIChildren数组中找不到该形式,则返回-1.如果您希望"1"表示顶部而不是0,只需将Result设置为i + 1.

That should return the depth of a child between 0 and n-1, where 0 is top, and -1 if the form is not found in the MDIChildren array. If you want "1" to mean top instead of 0, simply set Result to i+1 instead.

这篇关于如何检查"Z位置"是否正确?在MDI应用程序中的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆