Board index » delphi » How to change Zorder of TShape Componets ?

How to change Zorder of TShape Componets ?

Hi ! Happy New Year.

I make Graphic Editor Application in D4.

How to change Zorder of Tshape Components ?

I am programming using TControl.SendToBack and TControl.BringToFront Method.
But, One step Forward and Back Method  do not Implement.

How to Programming?

Thanks.

 

Re:How to change Zorder of TShape Componets ?


On Tue, 5 Jan 1999 11:10:09 +0900, "-??" <kmjz...@chollian.net>
wrote:

Quote
> How to change Zorder of Tshape Components ?

There are two separate z-orders, one for graphic controls (those
descended from TGraphicControl, such as TLabel or TShape) and another
for windowed controls (those descended from TWinControl, such as TEdit
or TPanel).

Graphic controls always appear behind windowed controls.

BringToFront and SendToBack work fine for both graphic controls and
windowed controls, within their z-order. The z-order also happens to
be the same as the order of the controls in the Controls property
(with the topmost being last). You can't modify the Controls property
directly (since it is read-only), but you can delete the controls from
the parent, and then re-add them in the desired z-order.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:How to change Zorder of TShape Componets ?


Quote
>BringToFront and SendToBack work fine for both graphic controls and
>windowed controls, within their z-order. The z-order also happens to
>be the same as the order of the controls in the Controls property
>(with the topmost being last). You can't modify the Controls property
>directly (since it is read-only), but you can delete the controls from
>the parent, and then re-add them in the desired z-order.

Hi, Rick

I can delete the Controls,
but how to re-add them in desired z-order.

Thanks.

From Myung-ju Kang

Re:How to change Zorder of TShape Componets ?


On Tue, 5 Jan 1999 17:29:50 +0900, "-??" <kmjz...@chollian.net>
wrote:

Quote
> but how to re-add them in desired z-order.

If you created them, you should know how to re-create them. Just
create the controls in the order you want. (A control is added to its
Parent's Controls property when you set its Parent property).

For example:

procedure TForm1.FormCreate(Sender: TObject);
var
  L: TLabel;
begin
  { First control in Controls property and z-order }
  L := TLabel.Create(Self);
  L.Parent := Self;
  { Second control in Controls property and z-order }
  L := TLabel.Create(Self);
  L.Parent := Self;
end;

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:How to change Zorder of TShape Componets ?


Ouch!

Am I missing something here? I thought we were discussing
removing a control and re-adding it. Why is a .Create needed?
Something *like* the example  from TWinControl.RemoveControl
shoud work.

Of course, If you just want to change the Zorder, just
call the bring to front method for each control in the
order you want them.

Joe

Quote
Rick Rogers (TeamB) wrote:

> On Tue, 5 Jan 1999 17:29:50 +0900, "-??" <kmjz...@chollian.net>
> wrote:

> > but how to re-add them in desired z-order.

> If you created them, you should know how to re-create them. Just
> create the controls in the order you want. (A control is added to its
> Parent's Controls property when you set its Parent property).

> For example:

> procedure TForm1.FormCreate(Sender: TObject);
> var
>   L: TLabel;
> begin
>   { First control in Controls property and z-order }
>   L := TLabel.Create(Self);
>   L.Parent := Self;
>   { Second control in Controls property and z-order }
>   L := TLabel.Create(Self);
>   L.Parent := Self;
> end;

> --
> Rick Rogers (TeamB) | Fenestra Technologies
> http://www.fenestra.com/

--
Joe C. Hecht
http://home1.gte.net/joehecht/index.htm

Re:How to change Zorder of TShape Componets ?


On Tue, 05 Jan 1999 15:05:24 -0600, "Joe C. Hecht" <joehe...@gte.net>
wrote:

Quote
> Why is a .Create needed?

Of course it .Create isn't needed; I merely used that as a gross
example to get the point across about the link between the Controls
property and the z-order. You are right, InsertControl and
RemoveControl would have made a better example.

Quote
> call the bring to front method

Righty-o. This has been mentioned both by the original poster and by
me, thought for some reason, the original poster doesn't wish to use
BringToFront or SendToBack. I'm not sure why; to be honest, I had some
difficulty in understanding the original question.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:How to change Zorder of TShape Componets ?


Quote
>> Why is a .Create needed?

>Of course it .Create isn't needed; I merely used that as a gross
>example to get the point across about the link between the Controls
>property and the z-order. You are right, InsertControl and
>RemoveControl would have made a better example.

This is sample code using RemoveControl and InsertControl Method.
Shape1 Component removed and Inserted in Control.
But, Shape1 is TopMost Order. I want to move one step Forward and Back

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  Temp: TControl;
begin
  for I := ControlCount - 1 downto 0 do
  begin
    Temp := Controls[I];
    if Temp.Name = 'Shape1' then
    begin
      RemoveControl(Shape1);
      InsertControl(Shape1);
    end;
  end;
end;

Thanks

From Myung-ju Kang.

Re:How to change Zorder of TShape Componets ?


On Wed, 6 Jan 1999 08:50:21 +0900, "-??" <kmjz...@chollian.net>
wrote:

Quote
>  I want to move one step Forward and Back

Okay, I'd probably use a TList. Here's an example to get you started:

procedure TForm1.Button1Click(Sender: TObject);
var
  List: TList;
  I : Integer;
begin
  List := TList.Create;
  try
    List.Add(Shape1);
    List.Add(Bevel1);
    List.Add(Label1);
    for I := 0 to List.Count - 1 do
      TControl(List[I]).BringToFront;
  finally
    List.Free;
  end;
end;

The z-order of the controls will be (from bottom to top): Shape1,
Bevel1, and Label1. You can populate a TList with all of the controls
in the parent, like this:

  for I := 0 to ControlCount - 1 do List.Add(Controls[I]);

And you can use the TList.Exchange method to swap any two TList items.
Once you've got the controls in the TList in the exact z-order you
want, iterate through the list, calling BringToFront (or SendToBack)
on each control, as illustrated above.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Other Threads