Solved

Top align problem

Posted on 2004-10-12
10
700 Views
Last Modified: 2010-04-05
I add into my component some buttons. My problem is that I wish to keep the order for alignement.

But1
But2
But3
...

When I create a new button and assign alTop I get:

But3
But2
But1

What to do?
0
Comment
Question by:ginsonic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 12287493
Add them in reverse order?
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12287851
No. Up is just a sample. I can add anytime, anyitem. In same time I'm interested how to move the But3 between but1 and but2.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12287896
At design time I've done reordering by switching alignment to alNone, repositioning and then switching back.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:ginsonic
ID: 12287957
I need on runtime!
0
 
LVL 17

Expert Comment

by:mokule
ID: 12288649
Hi,
what do You think about this.

procedure TForm1.Button1Click(Sender: TObject);
begin

Panel2.Align := alNone;
Panel3.Align := alNone;
Panel4.Align := alNone;

Panel2.Top := 0;
Panel3.Top := Panel2.Top+Panel2.Height;
Panel4.Top := Panel3.Top+Panel3.Height;

Panel2.Align := alTop;
Panel3.Align := alTop;
Panel4.Align := alTop;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin

Panel2.Align := alNone;
Panel3.Align := alNone;
Panel4.Align := alNone;

Panel4.Top := 0;
Panel3.Top := Panel4.Top+Panel4.Height;
Panel2.Top := Panel3.Top+Panel3.Height;

Panel4.Align := alTop;
Panel3.Align := alTop;
Panel2.Align := alTop;

end;
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12289991
Nope. This create a flickering.

One solution can be :

NewBut.Top:=MyVcl.Height;
NewBut.Align:=alTop;
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12290634
This may be of some help...

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21058579.html

It concerns hiding/showing, but the idea of setting alNone and moving the panel off form seems to help.

Flicker can be controlled (possibly) with LockWindowUpdate:

LockWindowUpdate(Form.handle);
try
  // realign panels
finally
  LockWindowUpdate(0);
end;
0
 

Expert Comment

by:joncmora
ID: 12296230
var
  LastPos, I: Integer;
  NewButton: TButton;
begin
  NewButton := TButton.Create(Self);  //assuming self is your component and it owns all the components inside it
  NewButton.Visible := False;
  NewButton.Parent := Self;
  LastPos := 0;
  for I := Self.ComponentCount - 2 downto 0 do
  begin
    if Self.Components[I] is TButton then
    begin
      LastPos := TButton(Self.Components[I]).Top + TButton(Self.Components[I]).Height;
      Break;
    end;
  end;
  NewButton.Left := 0;
  NewButton.Top := LastPos;// + 2 {we can add a few more pixels just to make sure the new button is below the last one.};
  NewButton.Visible := True;
  NewButton.Align := alTop;
  NewButton.Caption := IntToStr(Self.ComponentCount);
end;
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 12297071
hi ginsonic, i'd use a simple method:

the top of the new control shoulld be less than the bottom of the control on top, so the simplest way is:

procedure TForm1.AlignAfter(Control, After: TControl); //control is the control in creation, after the top control up the created
begin
   Control.Top := After.top+after.height-1; //to be sure that it's going between
   control.Align := alTop;
end;
now let's say that you have 3 panels with align altop

so

Panel1
Panel2
Panel3
using it as follows

procedure TForm1.Button1Click(Sender: TObject);
var
pnl: TPanel;
begin
pnl := TPanel.Create(self);
pnl.Caption := 'New Panel';
AlignAfter(Pnl,Panel2);
pnl.Parent := self;
end;

the order will be
Panel1
Panel2
New Panel
Panel3

really simply, or not?

F68 ;-)
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12298584
Thanks to all for support!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question