views:

111

answers:

1

Hi,

First, Please download this file ( download ).

how to i can set Form2 to "Send to back" for show Image1 to user ?? i use Image1.BringToFront; but this code not work!!

here is main unit:

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  A: 

The way you're doing it, many Form2 instances can be stacked over the image, so you can search for all child forms (I mean, all forms which parent is Form1) and hide each. Final result is image is shown again.

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;

Best regards.

jachguate