如何在运行时发送回控件?

时间:2010-10-26 22:53:30

标签: delphi delphi-xe

首先,请下载此文件(download)。

如何将Form2设置为“Send to back”以显示Image1给用户? 我使用Image1.BringToFront;但是这段代码不起作用!!

这是主要单位:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Image1: TImage;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
      uses unit2;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   tFrm2:Tform2;
begin
     tFrm2:=Tform2.Create(self);
     tFrm2.Parent:=self;
     tFrm2.Align:=alClient;
     tFrm2.Show;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
//     Image1.BringToFront;

end;

end.

1 个答案:

答案 0 :(得分:2)

您正在这样做,许多Form2实例可以堆叠在图像上,因此您可以搜索所有子表单(我的意思是,所有表单,其中父表单是Form1)并隐藏每个表单。最终结果是图像再次显示。

procedure TForm1.Button2Click(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to Screen.FormCount - 1 do
    if (Screen.Forms[I].Parent = Self) then
      Screen.Forms[I].Hide;
end;

最好的问候。